leifeld/texreg

Texreg threeparttable option in RMarkdown

tenAlf opened this issue · 3 comments

Hi there, I hope do not report anything already known.

When setting the option threeparttable = TRUE in texreg it automatically outputs "\usepackage{threeparttable}" as first line of code.
Used inside a .Rmd this leads to the file not being rendered and the error message: ! LaTeX Error: Can be used only in preamble.

This happens regardless of threeparttable already included in the header or not.
Here is a recreational example in form of .Rmd content

---
date: "2022-09-01"
output: pdf_document
header-includes:
- \usepackage{threeparttable}
---


```{r model, results='asis'}
fit <- lm(speed ~ dist, data = cars)
texreg::texreg(list(fit, fit),
       custom.note = paste("\\item[\\hspace{-5mm}] %stars.",
                           "\\item[\\hspace{-5mm}] This regression",
                           "should be interpreted with strong",
                           "caution as it is likely plagued by",
                           "extensive omitted variable bias."),
       single.row = TRUE,
       threeparttable = TRUE)
``

Have you tried the argument use.packages = FALSE?

Note that there is also a knitreg function for flexible switching between document types.

Damn, options are so amazingly many I missed that one... Sorry to bother and thanks for the quick reply!

No problem, you are welcome!