【发布时间】:2019-02-25 15:36:25
【问题描述】:
我一直在尝试在文档中显示表格。当我使用kable 时,docx 中的输出不会显示为表格。我可以使用pander 正确生成表格,但这不是最佳选择,因为我将无法生成标题。
---
title: "My Title"
output:
bookdown::word_document2:
fig_caption: yes
reference_docx: G:/My Drive/Projects/R15_Pipeline/R15Dir/styles/Brain_template.docx
bookdown::pdf_document2:
toc: no
link-citations: no
site: bookdown::bookdown_site
bibliography: G:/My Drive/ZoteroRPlugin/Report_references.bib
csl: G:/My Drive/ZoteroRPlugin/styles-master/dependent/brain.csl
---
```{r setup, include=FALSE, cache=FALSE, echo=FALSE}
#create a table
smoke <- matrix(c(51,43,22,92,28,21,68,22,9),ncol=3,byrow=TRUE)
colnames(smoke) <- c("High","Low","Middle")
rownames(smoke) <- c("current","former","never")
smoke <- as.data.frame(smoke)
```
Here is an example using pander where the table is displayed properly but no caption. For example Table \@ref(tab:table1)
```{r table1, echo = FALSE}
pander(smoke, booktabs=T, caption = "Descriptives per Group")
```
Here is an example using kable. Table \@ref(tab:table2) which does not work
```{r table2, echo = FALSE}
knitr::kable(smoke, format="markdown", caption = "Descriptives per Group")
```
【问题讨论】:
-
您的示例不可重现(我们没有您的 G: 驱动器)。当我删除这些行时,我不明白你的描述。所以也许你需要更新你的包,或者你 G 上的那些文件中可能有一些东西:驱动器搞砸了。
-
嗯,好的,谢谢,今晚晚些时候我会解决这个问题。感谢您的意见
-
感谢您的帮助。我能够找到错误的根源。虽然我不确定它为什么会发生。在我的代码中,我使用以下代码加载数据
标签: r-markdown knitr pandoc kable