2016-06-14 22 views
2

我成功地使用ztable,xtable或htmltable包生成表沒有問題。但是,我想知道這些表是否可以作爲pdf文檔輸出。當我嘗試編織pdf_output時,表格不顯示。相反,信息顯示爲多個字符串。我試過改變乳膠引擎(使用ztable)和其他方法,沒有運氣。RMarkdown pdf_output of ztable | xtable | htmlTable

我在這裏看了:
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)) 
``` 
+1

你在你的[R降價部分的標題使用'結果='asis''? – dash2

+0

當我嘗試ztable包時,我做了。讓我再試一次併發布輸出消息。 – Dania

+0

我做了以下錯誤(使用:'results ='asis''和稍後在代碼中:'options(ztable.type =「latex」)': 'pandoc.exe:從TeX源生成PDF時出錯' '錯誤:pandoc文檔轉換失敗,錯誤43' – Dania

回答

5

添加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)) 
```