幻灯片及其内容之间的交叉引用 [英] Cross references between slides and its content
问题描述
在具有输出格式 beamer
的R markdown演示文稿中(用于生成LaTex/PDF文件),是否可以在幻灯片(即最终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, i.e. pages of the final PDF?
This would be very helpful to quickly jump between slides, e.g. 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.
---
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}
如果检查由MWE生成的tex代码,您将看到表和图形都包含在没有标题或 figure
/ table
环境的情况下,但是您可以参考他们所在的幻灯片
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
- Bullet 1: \hyperlink{table}{table}
- Bullet 2: \hyperlink{plot}{plot}
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
方法2
,或者您可以使用 caption
包将标题添加到表格和绘图中
Approach 2
or you could use the caption
package to add captions to your tables and plots
---
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
将此用作 preamble.tex
:
\setbeamertemplate{caption}[numbered]
\usepackage{caption}
这篇关于幻灯片及其内容之间的交叉引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!