Search code examples
rlatexr-markdownmarkdownbeamer

Vertically center-align content of columns in a beamer presentation generated with rmarkdown


How to vertically center-align the content of multiple columns in a `rmarkdown::beamer_presentation?

As recommended in a comment in to an answer to this SO post, I tried ::: {.column width="30%"}, which however did not work for me.

enter image description here

If there is a simple way to align content differently for each column, that would further be very helpful too (e.g., c1: top, c2: middle, c3: bottom, c4: middle).

MWE

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

## Figures in columns top-aligned
::: columns

:::: {.column width="30%"}
```{r top-p-5, echo=FALSE, out.width='30%'}
plot(pressure[1:5,])
```
::::

:::: {.column width="30%"}
```{r top-p-10, echo=FALSE, out.width='50%'}
plot(pressure[1:10,])
```
::::

:::: {.column width="30%"}
```{r top-p-all, echo=FALSE, out.width='100%'}
plot(pressure[1:nrow(pressure),])
```
::::

:::

## Figures in columns center-aligned (not working)
::: columns

::: {.column width="30%"}
```{r center-p-5, echo=FALSE, out.width='30%'}
plot(pressure[1:5,])
```
:::

::: {.column width="30%"}
```{r center-p-10, echo=FALSE, out.width='50%'}
plot(pressure[1:10,])
```
:::

::: {.column width="30%"}
```{r center-p-all, echo=FALSE, out.width='100%'}
plot(pressure[1:nrow(pressure),])
```
:::

:::

Solution

  • You can use :::: {.columns align=center} to get centre alignment

    ---
    output:
      bookdown::pdf_book:
        base_format: rmarkdown::beamer_presentation
        slide_level: 2
        keep_tex: true
    ---
    
    ## Figures in columns top-aligned
    ::: columns
    
    :::: {.column width="30%"}
    ```{r top-p-5, echo=FALSE, out.width='30%'}
    plot(pressure[1:5,])
    ```
    ::::
    
    :::: {.column width="30%"}
    ```{r top-p-10, echo=FALSE, out.width='50%'}
    plot(pressure[1:10,])
    ```
    ::::
    
    :::: {.column width="30%"}
    ```{r top-p-all, echo=FALSE, out.width='100%'}
    plot(pressure[1:nrow(pressure),])
    ```
    ::::
    
    :::
    
    ## Figures in columns center-aligned (not working)
    :::: {.columns align=center}
    
    ::: {.column width="30%"}
    ```{r center-p-5, echo=FALSE, out.width='30%'}
    plot(pressure[1:5,])
    ```
    :::
    
    ::: {.column width="30%"}
    ```{r center-p-10, echo=FALSE, out.width='50%'}
    plot(pressure[1:10,])
    ```
    :::
    
    ::: {.column width="30%"}
    ```{r center-p-all, echo=FALSE, out.width='100%'}
    plot(pressure[1:nrow(pressure),])
    ```
    :::
    
    ::::
    

    enter image description here