Passing multiple frame options to a single frame in an rmarkdown::beamer_presentation
Asked Answered
B

1

3

How to pass several frame options to a specific frame in an rmarkdown::beamer_presentation?

In the MWE below, the second frame should contain the same table as on the frame before, just with a few more rows.

Thus,

  1. the page numbering is ideally the same for both frame (=> {.noframenumbering})

  2. to simply add the rows on frame 2 below those on frame 1, the content of both frame should be top-aligned (=> {.t}). Since some other slides require vertical center alignment of frame content, setting classoption: t in the YAML header would be undesired.

MWE

---
output:
  bookdown::pdf_book:
    base_format: rmarkdown::beamer_presentation
    slide_level: 2
    keep_tex: true
---

## Slide

```{r table, cars, echo = FALSE}
library(kableExtra)
knitr::kable(head(mtcars[1:3, 1:3]), caption = "Table caption")
```

## Slide {.noframenumbering}

```{r table, cars2, echo = FALSE}
library(kableExtra)
knitr::kable(head(mtcars[1:6, 1:3]), caption = "Table caption")
```

(adding multiple classoptions in the YAML-header is feasible by separating them with a comma, e.g. classoption: t, aspectratio=169. The same approach did not work for me in adjusting them for a single frame though, i.e., ## Slide {.noframenumbering,.t}.)

Buckshot answered 22/2, 2021 at 8:4 Comment(0)
M
3

You can use the following syntax to pass multiple options to a frame:

---
output:
  bookdown::pdf_book:
    base_format: rmarkdown::beamer_presentation
    slide_level: 2
    keep_tex: true
---

## Slide {.t}

```{r table, cars, echo = FALSE}
library(kableExtra)
knitr::kable(head(mtcars[1:3, 1:3]), caption = "Table caption")
```

## Slide {.noframenumbering .t}

```{r table, cars2, echo = FALSE}
library(kableExtra)
knitr::kable(head(mtcars[1:6, 1:3]), caption = "Table caption")
```

With pandoc 2.17.1.1 or newer, frame options are now much easier:

---
output:
  bookdown::pdf_book:
    base_format: rmarkdown::beamer_presentation
    slide_level: 2
    keep_tex: true
---

## Slide {frameoptions="t"}

```{r table, cars, echo = FALSE}
library(kableExtra)
knitr::kable(head(mtcars[1:3, 1:3]), caption = "Table caption")
```

## Slide {frameoptions="noframenumbering,t"}

```{r table, cars2, echo = FALSE}
library(kableExtra)
knitr::kable(head(mtcars[1:6, 1:3]), caption = "Table caption")
```
Mcripley answered 22/2, 2021 at 9:6 Comment(2)
Thank you very much for your quick response! So my question should better read "Passing multiple frame options to a ...". Would it be OK if rename it for correctness now ex-post?Buckshot
@Buckshot Sure, I will adapt my answer to your editMcripley

© 2022 - 2024 — McMap. All rights reserved.