【发布时间】:2021-05-23 07:45:28
【问题描述】:
在使用bookdown 编制的较大报告中,我使用了几个kableExtra 表格,其中包括LaTex commands(例如,添加斜体字、项目符号以创建列表,以及在表格中手动添加脚注)。
当我复制使用rmarkdown::beamer_presentation 生成的LaTex beamer presentation 中的表时,不幸的是编译失败了。
如何扭曲kableExtra 表以包含LaTex commands?
MWE
---
title: "MWE"
subtitle: "Beamer presentation with R-markdown"
author: "Donald Duck"
institute: "some place"
date: "`r format(Sys.time(), '%B %d, %Y')`"
output:
bookdown::pdf_book:
base_format: rmarkdown::beamer_presentation
theme: "THEMENAME"
latex_engine: xelatex
toc: false
slide_level: 2
---
(ref:footnote-a) Text for footnote a
(ref:footnote-b) Text for footnote b
\renewcommand{\arraystretch}{1.3} <!-- increase line spacing for the table -->
```{r table-wLatex, echo=FALSE, fig.align="center", message=FALSE, warning=FALSE, out.width='66%'}
library(kableExtra)
library(dplyr)
# table with manually added footnotes within table
df <- data.frame(
col1 = c("Category 1", "Category 2"),
col2 = c(
"foo and \\emph{special foo}$^{a}$",
"bar and \n $\\boldsymbol{\\cdot}$ \\emph{random bar}$^{a}$\n $\\boldsymbol{\\cdot}$ \\emph{special bar}$^{b}$")
)
# header: add column names
names(df) <- c("Categories", "Description")
df %>%
mutate_all(linebreak) %>% # required for linebreaks to work
kable(
"latex",
# escape = FALSE, # needed to be able to include latex commands
booktabs=TRUE,
align = "l",
caption = "Caption Table with LaTex" # short caption for LoT
) %>%
kableExtra::footnote(
alphabet = c(
"(ref:footnote-a)",
"(ref:footnote-b)"
),
threeparttable = TRUE, # important! Else footnote runs beyond the table
footnote_as_chunk = TRUE, title_format = c("italic", "underline")
) %>%
column_spec(1, width = "11em") %>% # fix width column 1
column_spec(2, width = "27em") # fix width column 2
```
\renewcommand{\arraystretch}{1} <!-- reset row height/line spacing -->
【问题讨论】:
-
escape = FALSE被禁用了吗? -
@bttomio:以前在
bookdown中没有被禁用。但是对于beamer必须禁用它 - 否则将无法编译。
标签: r latex r-markdown beamer xelatex