TransWikia.com

include latex table in rmarkdown

TeX - LaTeX Asked by Jaynes01 on December 2, 2020

I try to include latex code (a table) into my Rmarkdown document. I need to use latex instead of other options because the table has to be in a certain format.

The problem I encounter is the following error:

! LaTeX Error: Environment threeparttable undefined.
Error: Failed to compile confounder_table.tex. See
confounder_table.log for more info. Execution halted

This is the table I include in the .Rmd document. I want to render it to pdf and/or docx and I use knitr for that (all in Rstudio). After working on that for 2 hours I hope that you can give me a hint how to solve this. It works for docx and html but not for the pdf format.

This is table code:

begin{table}[tbp]
begin{center}
begin{threeparttable}
caption{Descriptive statistics included in the present study.}
begin{tabular}{ll}
toprule
cyl & multicolumn{1}{c}{Some columnname}
midrule
4.00 & 26.66 ± 4.51
6.00 & 19.74 ± 1.45
8.00 & 15.1 ± 2.56
bottomrule
addlinespace
end{tabular}
begin{tablenotes}[para]
textit{Note.} There were no signnificant differences in the means between the groups.
end{tablenotes}
end{threeparttable}
end{center}
end{table}

2 Answers

I found the solution: I had to load a specific library for that with:

library(kableExtra)

Answered by Jaynes01 on December 2, 2020

If you are using bookdown, there is explicit functionality to handle this. You just need to handle the LaTeX with the following:

```{=latex}

         [PUT LATEX HERE]      

```

This feature requires a Pandoc version higher than 2.0 (check markdown::pandoc_version()).

If you have the right pandoc version, you would do:

```{=latex}

begin{table}[tbp]
begin{center}
begin{threeparttable}
caption{Descriptive statistics included in the present study.}
begin{tabular}{ll}
toprule
cyl & multicolumn{1}{c}{Some columnname}
midrule
4.00 & 26.66 ± 4.51
6.00 & 19.74 ± 1.45
8.00 & 15.1 ± 2.56
bottomrule
addlinespace
end{tabular}
begin{tablenotes}[para]
textit{Note.} There were no signnificant differences in the means between the groups.
end{tablenotes}
end{threeparttable}
end{center}
end{table}

```

Here's an example using the bookdown package for longer documents: https://bookdown.org/yihui/rmarkdown-cookbook/raw-latex.html

Answered by HoneyBuddha on December 2, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP