modelsummary: latex output, label wrongly displayed

31 views Asked by At

I have a small question. Suppose I run the following code.


#Dummy model:
set.seed(1)
dummy_model <- lm(rnorm(100) ~ rnorm(100))

#Table:
modelsummary(
  dummy_model,
  output = "latex",
  fmt  = 3,
  estimate = "{estimate}",
  gof_omit = 'DF|Deviance|R2|AIC|BIC|Log.Lik.|Std.Errors|FE|Num.Obs.|F|RMSE',
  title = "\\label{my_label}My Table",
  stars = FALSE,
  booktabs = TRUE,
)

It produces the following output:

\begin{table}

\caption{\label{my\_label}My Table}
\centering
\begin{tabular}[t]{lc}
\toprule
  & (1)\\
\midrule
(Intercept) & \num{0.109}\\
 & (\num{0.090})\\
\bottomrule
\end{tabular}
\end{table}

Instead of getting my_label I get my\_label. Is there a way to get a correct label?

1

There are 1 answers

0
Peter On BEST ANSWER

Add escape = FALSE to the call to modelsummary

library(modelsummary)
modelsummary(
  dummy_model,
  output = "latex",
  fmt  = 3,
  estimate = "{estimate}",
  gof_omit = 'DF|Deviance|R2|AIC|BIC|Log.Lik.|Std.Errors|FE|Num.Obs.|F|RMSE',
  title = "\\label{my_label}My Table",
  stars = FALSE,
  booktabs = TRUE,
  escape = FALSE
)

Produces:

\begin{table}
\centering
\caption{\label{my_label}My Table}
\centering
\begin{tabular}[t]{lc}
\toprule
  & (1)\\
\midrule
(Intercept) & \num{0.109}\\
 & (\num{0.090})\\
\bottomrule
\end{tabular}
\end{table}