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

问题描述

输出格式为 beamer生成 LaTex/PDF 文件)的 R markdown 演示文稿中,是否可以在幻灯片之间创建交叉引用,即最终 PDF 的页面? 这对于在幻灯片之间快速跳转非常有帮助,例如导航到演示文稿末尾的附录。

我尝试使用本 SO post 中建议的 bookdown 命令,但没有成功。

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

解决方法

要链接到附录,您可以使用

- Bullet 3: \hyperlinkappendixstart{appendix}

如果您检查 MWE 生成的 tex 代码,您将看到您的表格和图形都包含在没有标题或 figure/table 环境的情况下,但您可以参考它们所在的幻灯片

- 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 包为您的表格和绘图添加标题

---
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,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}

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...