【问题标题】:RMarkdown pdf_output of ztable | xtable | htmlTableztable 的 RMarkdown pdf_output |表格 | html表
【发布时间】:2016-06-14 13:22:51
【问题描述】:

我使用 ztable、xtable 或 htmlTable 包成功地生成了表格,没有任何问题。但是,我想知道这些表格是否可以输出为 pdf 文档。当我尝试编织 pdf_output 时,该表未显示。相反,信息显示为几个字符串。我尝试过更改乳胶引擎(使用ztable)和其他方法,但没有成功。

我看过这里:
http://www.mzan.com/article/29773068-rmarkdown-latex-table-output-difficulties.shtml

我也看过小插曲等。

示例(RMarkdown):

---  
output: pdf_document
---

```{r, message = F, results = 'asis'} 
# will throw out Error: pandoc document conversion failed with error 43
library(ztable)
data(iris)
options(ztable.type="latex") 
zt <- ztable(iris[1:5,], caption = "ztable")
zt <- addcgroup(zt,
                cgroup = c("group 1", "group 2"),
                n.cgroup = c(2,3))
print(zt)
```  

```{r, message = F }
# since it's html, will produce text only
library(htmlTable)
data(mtcars)
colnames(mtcars) <- NULL
htmlTable(mtcars[1:5,], caption = "htmlTable",
          cgroup = c("group 1", "group 2"),
          n.cgroup = c(5,6))
```

【问题讨论】:

  • 您是否在 R 降价部分的标题中使用 results='asis'
  • 我在尝试 ztable 包时这样做了。让我再试一次并发布输出消息。
  • 这将有助于查看表中包含的内容。有_#$等字符吗?我经常忘记用反斜杠转义这些字符,导致这样的错误。没有可重复的例子很难说。
  • 另外,如果你有变音符号(基本上,如果你不是用英文写的话),试着在你的 yaml 前端设置 latex_engine: xelatex
  • 当我将header-includes: \usepackage{colortbl} 添加到前端时,这个示例对我有用。 (对于ztable。我认为htmlTable 没有html 引擎)

标签: r r-markdown


【解决方案1】:

添加header-includes: \usepackage{colortbl} 可解决ztable 的错误。我认为htmlTable 没有乳胶引擎。

完整代码:

---  
output: pdf_document
header-includes: \usepackage{colortbl}
---

```{r, message = F, results = 'asis'} 
library(ztable)
data(iris)
options(ztable.type="latex") 
zt <- ztable(iris[1:5,], caption = "ztable")
zt <- addcgroup(zt,
                cgroup = c("group 1", "group 2"),
                n.cgroup = c(2,3))
print(zt)
```  

```{r, message = F }
# since it's html, will produce text only
library(htmlTable)
data(mtcars)
colnames(mtcars) <- NULL
htmlTable(mtcars[1:5,], caption = "htmlTable",
          cgroup = c("group 1", "group 2"),
          n.cgroup = c(5,6))
```

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多