vincentarelbundock / modelsummary

Beautiful and customizable model summaries in R.
http://modelsummary.com
Other
911 stars 75 forks source link

Recommended method for adding LaTeX labels now requires an additional option #774

Closed NickCH-K closed 4 months ago

NickCH-K commented 4 months ago

The recommended approach to adding a LaTeX label is to add it as a text string in the caption. From the help file for modelsummary (with output = 'latex' added):

library(modelsummary)

# load data and estimate models
utils::data(trees)
models <- list()
models[['Bivariate']] <- lm(Girth ~ Height, data = trees)
models[['Multivariate']] <- lm(Girth ~ Height + Volume, data = trees)

modelsummary(models, title = 'This is the title \\label{tab:description}',
             output = 'latex')
# includes this line: 
# caption={This is the title \textbackslash{}label\{tab:description\}},

This problem is solved with escape = FALSE but this is not reflected in the docs (or your stackoverflow answer

modelsummary(models, title = 'This is the title \\label{tab:description}',
             output = 'latex', escape = FALSE)
# works:
# caption={This is the title \label{tab:description}},
vincentarelbundock commented 4 months ago

Good catch. Thanks for raising the issue.

And sorry for the breaking change. The escape argument did not used to apply to title because of a limitation in kableExtra. This was inconsistent since the body would be escaped but not the notes or title. Now, the argument applies more evenly.

I edited the SO answer, changed the example in the documentation, the Quarto example document, and improved the man page:

   title: string. Cross-reference labels should be added with Quarto or
          Rmarkdown chunk options when applicable. When saving
          standalone LaTeX files, users can add a label such as
          \\label{tab:mytable} directly to the title string, while also
          specifying ‘escape=FALSE’.