! LaTeX错误:环境三部分表未定义

! LaTeX错误:环境三部分表未定义,latex,pdf-generation,r-markdown,Latex,Pdf Generation,R Markdown,使用R Markdown创建pdf时,出现以下错误: output file: NCERA-210_Results.knit.md ! LaTeX Error: Environment threeparttable undefined. Error: Failed to compile NCERA-210_Results.tex. See NCERA-210_Results.log for more info. In addition: There were 50 or more warni

使用R Markdown创建pdf时,出现以下错误:

output file: NCERA-210_Results.knit.md

! LaTeX Error: Environment threeparttable undefined.

Error: Failed to compile NCERA-210_Results.tex. See NCERA-210_Results.log for more info.
In addition: There were 50 or more warnings (use warnings() to see the first 50)
Execution halted
我的代码是:

---
title: "NCERA-210 Results"
author: "NAME"
date: "8/29/2018"
output: pdf_document
---

```{r setup, echo=FALSE, results="asis", message=FALSE, warning=FALSE}

# load packages
library("MOTE")
library("tidyverse")
library("broom")
library("ggpubr")
library("markovchain")
library("gmodels")
library("scales")
library("formattable")
library("rmarkdown")
library("knitr")
library("igraph")
library("papaja")
library("citr")
```

```{r, echo=FALSE, results="hide", message=FALSE, warning=FALSE,       
fig.show="hide"} 
source("Thesis_Code.R")  
```

## Summary of Ratings
```{r 'Table Rating Count', echo=FALSE, message=FALSE, warning=FALSE, results="asis"}
apa_table(rating.dist,
caption = "Count of Ratings in Dataset")
```

## Plot of Rating Distribution
```{r 'Plot of Rating Distribution', echo=FALSE, message=FALSE, warning=FALSE, results="asis"}

ggplot(rating.dist,
   aes(Rating, Count)) + 
geom_col() +
ggtitle("Distribution of Ratings")
```

## Summary of Short Ratings
```{r 'Table Short Rating Count', echo=FALSE, message=FALSE, warning=FALSE, results="asis"}
apa_table(s_rating.dist,
caption = "Count of Short Ratings in Dataset")
```

## Plot of Short Rating Distribution
```{r 'Plot of Short Rating Distribution', echo=FALSE, message=FALSE, warning=FALSE, results="asis"}

ggplot(s_rating.dist,
   aes(Short_Rating, Count)) + 
geom_col() +
ggtitle("Distribution of Short Ratings")
```

## Summary of Co-op Location Distribution
```{r 'Co-op Distribution', echo=FALSE, message=FALSE, warning=FALSE, results="asis"}
apa_table(state.dist,
caption = "Location Distribution in Dataset")
```

## Plot of Co-op Distribution
```{r 'Plot of Co-op Distribution', echo=FALSE, message=FALSE, warning=FALSE, results="asis"}

ggplot(state.dist,
   aes(State, Count)) + 
geom_col() +
ggtitle("Distribution of Cooperatives Across the U.S.")
```

## Co-op Activity
```{r 'Co-op Activity Summary',echo=FALSE, message=FALSE, warning=FALSE, results="asis"}

apa_table(coop_activity,
      caption = "Count of Co-ops by Activity")
```

## Co-op Sales Quartiles by Decade & Short Rating
```{r 'Sales Quartiles', echo=FALSE, message=FALSE, warning=FALSE, results="asis"}

apa_table(sales.qt,
caption = "Co-op Sales Quartiles by Decade & Short Rating")
```

## Co-op Liabilities by Decade & Short Rating
```{r 'Liabilities Quartiles', echo=FALSE, message=FALSE, warning=FALSE, results="asis"}

apa_table(liab.qt,
caption = "Co-op Liabilities Quartiles by Decade & Short Rating")
```

## Co-op Cash Patronage Paid by Decade & Short Rating
```{r 'Cash Patronage Paid Quartiles', echo=FALSE, message=FALSE, warning=FALSE, results="asis"}

apa_table(pat.paid,
      caption = "Co-op Cash Patronage Paid Quartiles by Decade & Short Rating")
```
我正在使用papaja软件包制作APA风格的手稿。我可以用Rmd脚本创建word文档,但当输出为pdf_文档时会出现错误。但是,我可以使用papaja模板“APA文章(第6版)”创建一份手稿,但这需要大量的脚本编辑来删除不必要的代码


我想这个问题与threepartabble有关,但我似乎找不到任何关于使用R的指导。我使用Mac并安装了MacTex。

由于某种原因,修复程序安装了“kableExtra”,pdf没有它就无法呈现。

这个建议的解决方案似乎不再有效

请参阅以下线程:对于新解决方案,它需要通过运行来更新RMarkdown:

remotes::install_github('rstudio/rmarkdown')
这将纠正threeparttablex latex软件包与rmarkdown之间的冲突。如果bookdown没有自动安装软件包,您可能还必须运行以下操作才能手动安装软件包:

library(tinytex)
tlmgr_install('threeparttablex')    # install the threeparttablex package
tlmgr_update()               # update everything
最后,我发现有必要终止您的R会话并重新启动,这样就可以使用rmarkdown包和更新的latex包。之后,您可以使用apa_表,并使用results='as-is',例如:

```{r apatable, results='asis'}

  apa_table(head(iris, 20), caption = 'Here is a nice table!')  

```

此外,bookdown还将像处理自己的knitr::kable表一样处理标签问题。

您能提供一个文档的最简单示例吗?谢谢,但最好编辑答案以包含额外的细节:)注释会弄乱文档formatting@MikeyHarper我在问题中加入了我的代码。我也有同样的问题。修复工作正常,但我也需要在我的环境中加载
kableExtra
。我只是想分享它的这一方面。感谢发布您的解决方案。此解决方案似乎不再工作。请查看以下线程以了解新解决方案,它需要对RMarkdown进行更新:remotes::install_github('rstudio/RMarkdown')