简体   繁体   English

幻灯片及其内容之间的交叉引用

[英]Cross references between slides and its content

In an R markdown presentation with output format beamer (to generate a LaTex/PDF file), is it possible to create cross-references between slides, ie pages of the final PDF? In an R markdown presentation with output format beamer (to generate a LaTex/PDF file), is it possible to create cross-references between slides, ie pages of the final PDF? This would be very helpful to quickly jump between slides, eg to navigate to an appendix at the end of the presentation.这对于在幻灯片之间快速跳转非常有帮助,例如在演示结束时导航到附录。

I tried to use bookdown commands as proposed in this SO post , but without success.我尝试使用此SO post中提出的 bookdown 命令,但没有成功。

MWE: MWE:

---
title: "Cross references between slides"
output:
  # beamer_presentation: default
  bookdown::pdf_book:
    base_format: rmarkdown::beamer_presentation
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

## Bullets with references

- Bullet 1: \ref{tab:my-table}
- Bullet 2: \ref{fig:my-plot}
- Bullet 3: \ref{appendix}

## Bullets with references (bookdown)

- Bullet 1: \@ref(tab:my-table)
- Bullet 2: \@ref(fig:my-plot)
- Bullet 3: \@ref(appendix)

## table

```{r my-table, cars, echo = TRUE}
library(kableExtra)
kable(summary(cars))
```

## plot

```{r my-plot, pressure}
plot(pressure)
```

## appendix

my appendix

For linking to the appendix, you can use要链接到附录,您可以使用

- Bullet 3: \hyperlinkappendixstart{appendix}

If you examine the tex code produced by your MWE you will see that your table and figure are both included without caption or figure / table environment, but you can reference the slide they are on如果您检查 MWE 生成的 tex 代码,您会看到您的表格和图形都包含在没有标题或figure / table环境的情况下,但您可以参考它们所在的幻灯片

- Bullet 1: \hyperlink{table}{table}
- Bullet 2: \hyperlink{plot}{plot}

MWE: MWE:

---
title: "Cross references between slides"
output:
  beamer_presentation:
    theme: "default"
    keep_tex: true
    includes:
      in_header: preamble.tex    

---


```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

## Bullets with references

- Bullet 1: \hyperlink{table}{table}
- Bullet 2: \hyperlink{plot}{plot}
- Bullet 3: \hyperlinkappendixstart{appendix}


## table


```{r my-table, cars, echo = TRUE}
library(kableExtra)
kable(summary(cars))
```

## plot


```{r my-plot, pressure}
plot(pressure)
```

## appendix
\appendix
my appendix

Approach 2方法二

or you could use the caption package to add captions to your tables and plots或者您可以使用caption package 为表格和绘图添加标题

---
title: "Cross references between slides"
output:
  beamer_presentation:
    theme: "default"
    keep_tex: true
    includes:
      in_header: preamble.tex    

---


```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

## Bullets with references

- Bullet 1: \ref{foo}
- Bullet 2: \ref{bar}
- Bullet 3: \hyperlinkappendixstart{appendix}


## table


```{r my-table, cars, echo = TRUE}
library(kableExtra)
kable(summary(cars))
```
\captionof{table}{foo}
\label{foo}

## plot


```{r my-plot, pressure}
plot(pressure)
```
\captionof{figure}{bar}
\label{bar}

## appendix
\appendix
my appendix

using this as preamble.tex :使用它作为preamble.tex

\setbeamertemplate{caption}[numbered]
\usepackage{caption}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM