【问题标题】:Vertically center-align content of columns in a beamer presentation generated with rmarkdown使用 rmarkdown 生成的投影仪演示文稿中的列内容垂直居中对齐
【发布时间】:2021-05-24 13:15:46
【问题描述】:

如何在 `rmarkdown::beamer_presentation 中垂直居中对齐多个列的内容?

正如对this SO post 的回答中的评论所建议的那样,我尝试了::: {.column width="30%"},但这对我不起作用。

如果有一种简单的方法可以为每一列以不同方式对齐内容,那也将非常有帮助(例如,c1:顶部,c2:中间,c3:底部,c4:中间) .

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),])
```
:::

:::

【问题讨论】:

    标签: r latex r-markdown markdown beamer


    【解决方案1】:

    您可以使用:::: {.columns align=center} 获得居中对齐

    ---
    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),])
    ```
    :::
    
    ::::
    

    【讨论】:

    • 感谢您的快速回复!不幸的是,你的提议对我不起作用。我的 sessionInfo R version 4.0.2 (2020-06-22), Platform: x86_64-apple-darwin17.0 (64-bit), Running under: macOS Catalina 10.15.6, knitr_1.30, rmarkdown_2.5
    • @mavericks 它似乎与 rstudio cloud R version 4.0.3 (2020-10-10) -- "Bunny-Wunnies Freak Out" 上的rstudio.cloud/project/2224516 一起工作
    • 可以确认在 rstudio cloud 上工作。更新“bookdown”、“kableExtra”、“knitr”、“markdown”并没有帮助。今天晚些时候将尝试升级到R 4.0.3
    • @mavericks 你也检查过 pandoc 的版本吗?
    • @marvericks 截至 2021 年 2 月 24 日,最新的 pandoc 版本为 2.11.4。您的可能“太旧”而无法获得居中对齐的列。如果您愿意,This chapter of R Markdown Cookbook 会指导您使用未与 RStudio IDE 捆绑的 Pandoc 版本。
    【解决方案2】:

    为了补充来自@samcarter_is_at_topanswers.xyz 的有用答案,可以采用以下方法在每列中以不同方式对齐内容:

    ---
    output:
      bookdown::pdf_book:
        base_format: rmarkdown::beamer_presentation
        slide_level: 2
        keep_tex: true
    ---
    
    ```{r echo=FALSE}
    # CHECK PANDOC VERSION
    library(rmarkdown)
    if (pandoc_available())
      cat("pandoc", as.character(pandoc_version()), "is available\n (pandoc >2.11.2 is required)")
    ```
    
    ## Figures in columns center-aligned (set for all columns at once)
    :::: {.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),])
    ```
    :::
    
    ::::
    
    
    ## Figures in columns aligned differently (set for separately for each column)
    :::: {.columns}
    
    ::: {.column width="30%" align=center}
    center
    ```{r 3-center-p-5, echo=FALSE, out.width='30%'}
    plot(pressure[1:5,])
    ```
    :::
    
    ::: {.column width="30%" align=top}
    top
    ```{r 3-top-p-10, echo=FALSE, out.width='50%'}
    plot(pressure[1:10,])
    ```
    :::
    
    ::: {.column width="30%" align=bottom}
    bottom
    ```{r 3-bottom-p-all, echo=FALSE, out.width='100%'}
    plot(pressure[1:nrow(pressure),])
    ```
    :::
    
    ::::
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-07
      • 2021-05-19
      • 1970-01-01
      • 2011-03-02
      • 1970-01-01
      • 2018-01-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多