我一直试图在文档中显示表格。当我使用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")
```
答案 0 :(得分:0)
感谢您的帮助。我能够找到错误的来源。虽然我不确定为什么会这样。在我的代码中,我使用以下代码加载数据
pacman::p_load(apastats,kableExtra, grid, captioner, citr)
#devtools::install_github("haozhu233/kableExtra", force = T)
load("data/data.RData") #load the data from createTablePlots.R
load("data/data2.RData") #load the data from newStatsSigTables.R
load("data/tables.RData") #load the data from createTablePlots.R
load("data/TrialErrorsTables.RData") #load the data from newStatsSigTable.R
load("data/statsProj2.RData")
此代码将导致错误,如屏幕截图所示。经过一番尝试和错误之后,该错误似乎与kableExtra
软件包冲突。当我从行中删除此程序包时,我可以获得正确的输出。我已经将其报告为KableExtra的GitHub上的错误