1

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.

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
Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
mavericks
  • 1,005
  • 17
  • 42

1 Answers1

2

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

- 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

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

using this as preamble.tex:

\setbeamertemplate{caption}[numbered]
\usepackage{caption}
  • Thanks a lot for the proposal. As far as I can see this simply jumps to the last page in the presentation. That is if the appendix contains several slides it would jump to the last slide of the appendix. (My presentation contains several "parts"; the appendix contains slides for each part which I would like to separate if feasible. Ideally, a general cross-reference would jump to the beginning of the appendix; as well as specific ones to specific parts/figs/tables of the appendix) – mavericks Feb 15 '21 at 17:51
  • @mavericks it jumps to the first slide of the appendix, or more preciously to were `\appendix` is located in the code, (the document will have to be compiled at least two times) – samcarter_is_at_topanswers.xyz Feb 15 '21 at 17:55
  • thank you very much for your very helpful and elaborate answer, which is greatly appreciated! – mavericks Feb 16 '21 at 10:33
  • An advantage of the second approach is that, while slide titles might change during the preparation of a presentation, labels for figures and tables are likely stable over time – mavericks Feb 16 '21 at 10:46
  • @MacUsers: Links might not necessarily work in presentation mode => Open presentation in Adobe Acrobat for Links to work properly in presentation mode – mavericks Feb 16 '21 at 10:53
  • @mavericks I would recommend adobe anyway, as the native mac viewer does not support automatic slide transitions etc. – samcarter_is_at_topanswers.xyz Feb 16 '21 at 10:57
  • true! Would you have any recommendations on how to display notes during the LaTeX Beamer presentation? E.g., by displaying the notes on a separate screen? – mavericks Feb 16 '21 at 12:42
  • @mavericks For a two-screen setup, I'm rather fond of this pdf viewer: http://iihm.imag.fr/blanch/software/osx-presentation/ – samcarter_is_at_topanswers.xyz Feb 16 '21 at 13:17
  • this looks like a very interesting tool! Thank you so much for the hint! – mavericks Feb 16 '21 at 13:46