【问题标题】:Using booktabs with Rmarkdown使用带有 Rmarkdown 的 booktabs
【发布时间】:2015-06-11 12:36:57
【问题描述】:

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。

【问题讨论】:

    标签: r r-markdown xtable


    【解决方案1】:

    尝试包含一个文件header.tex,您在该文件中依赖于 booktabs 包。详情请见the latex options rmarkdown。

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

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

    之后,样本 xtable 输出与 booktabs 一起出现。

    【讨论】:

    • 是的,可以解决它,但由于 pandoc 似乎无论如何都包含 booktabs,我不明白为什么没有外部 .tex 文件它就不能工作。 github.com/jgm/pandoc-templates/blob/master/default.latex$if(tables)$ \usepackage{longtable,booktabs} $endif$
    • 所以尝试启用选项tables
    • 关于如何做到这一点的文档不是特别清楚。经过一番反复试验,我发现output: pdf_document tables: true 无需借助外部 .tex 文件即可解决问题。
    • 亲爱的@r.bot,感谢花时间阅读并回答您问题的人的惯用方式是支持或接受这样的答案,而不是未经询问就闯入和编辑它。感谢 pc-shooter 恢复。
    • 抱歉打扰了,我无意冒犯。我只是想确保完整的解决方案在答案本身而不是讨论中。我以后不会这样做了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-24
    • 2017-05-18
    • 1970-01-01
    • 2017-10-11
    • 2021-02-19
    • 1970-01-01
    相关资源
    最近更新 更多