r - 在 Rmarkdown 中使用 booktabs

标签 r r-markdown xtable

Booktabs 和 xtable 因使用 RStudio 的 Rmarkdown 而失败。 Tufte 模板工作正常,但使用标准 .Rmd文件失败并显示错误消息:

! Undefined control sequence.
l.133   \toprule

pandoc.exe: Error producing PDF from TeX source
Error: pandoc document conversion failed with error 43

一个可重现的例子:
---
title: "Testing booktabs"
author: "r.bot"
date: "11 June 2015"
output: pdf_document
---

```{r, results='asis'}
library(xtable)
options(xtable.comment = FALSE)
options(xtable.booktabs = TRUE)
xtable(head(mtcars[,1:6]), caption = "First rows of mtcars")
```

R 版本 3.1.2 (2014-10-31)
平台:x86_64-w64-mingw32/x64(64位)
已安装最新版本的 Pandoc。

最佳答案

尝试包含一个文件 header.tex其中您依赖于 booktabs 包。见 the latex options rmarkdown 了解详情。

编辑:虽然包含标题很方便并且允许进行更广泛的更改,但我们在这里使用顶级选项 tables: true .所以上面例子的最小变化是

---
title: "Testing booktabs"
author: "r.bot"
date: "June 11, 2015"
output: pdf_document
tables: true
---

之后 sample xtable输出与 booktabs 一起出现。

关于r - 在 Rmarkdown 中使用 booktabs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30780998/

相关文章:

在具有多个匹配项的 data.table 中滚动连接

r - 如何最好地将嵌套列表展平为 R 中的 data.frame?

r - huxtable 表的单元格内的换行符

r - 如何减少 tableOutput Shiny 中的行高?

R、knitr、xtable、交替行颜色

r - 在 knitr 中左对齐 xtable 标题

使用 systemfit 进行 R SUR 回归导致错误 : LU computationally singular: ratio of extreme entries

r - R 包中的数据弃用

r - 将 R 文件转换为 R markdown 时出现问题

r - 在 RStudio 中,有没有办法为此文件的*所有*图形指定 fig.path?