“modelsummary”的“latex”输出功能需要哪些软件包?

问题描述 投票:0回答:1

喜欢

modelsummary
包,但自从更新到最新版本后,我什至无法在 Overleaf 中获得最简单的回归表来编译而不会出现错误。

考虑以下 R 代码:

library("groundhog") # for temporal reproducibility
meta.groundhog(date = "2024-04-30")
groundhog.library("modelsummary", date = "2024-04-30")

set.seed(05232024) # for result reproducibility

x <- rnorm(100)
y <- x*2 + rnorm(100)

fit <- lm(y ~ x)

modelsummary(fit, output = "latex")

生成以下 LaTeX 代码:

\begin{table}
\centering
\begin{tblr}[         %% tabularray outer open
]                     %% tabularray outer close
{                     %% tabularray inner open
colspec={Q[]Q[]},
column{1}={halign=l,},
column{2}={halign=c,},
hline{6}={1,2}{solid, 0.05em, black},
}                     %% tabularray inner close
\toprule
& (1) \\ \midrule %% TinyTableHeader
(Intercept) & 0.010    \\
& (0.093)  \\
x           & 1.868    \\
& (0.086)  \\
Num.Obs.    & 100      \\
R2          & 0.827    \\
R2 Adj.     & 0.825    \\
AIC         & 272.5    \\
BIC         & 280.3    \\
Log.Lik.    & -133.254 \\
F           & 468.067  \\
RMSE        & 0.92     \\
\bottomrule
\end{tblr}
\end{table} 

如果我将其放入带有 TeX 安装的文本编辑器(或 Overleaf,我尝试了几种不同的方式),我总是会收到错误。我用

\usepackage{tabularray}
\usepackage{booktabs}
。根据我的阅读,不清楚我是否需要其他软件包,但也许我遗漏了一些东西?我尝试更新我的 TeX 安装,使用 Overleaf 等。

背面错误消息:

<argument> \color 
                  {\l__tblr_f_tl }
l.42 \end
         {tblr}
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

我错过了什么吗?是否可以返回到旧的

modelsummary
输出?

我能想到的唯一一件事是

modelsummary
在加载时返回此消息:

`modelsummary` 2.0.0 now uses `tinytable` as its default table-drawing
  backend. Learn more at: https://vincentarelbundock.github.io/tinytable/

Revert to `kableExtra` for one session:

  options(modelsummary_factory_default = 'kableExtra')

但我不认为这是问题所在,因为我尝试恢复到

kableExtra
,但结果相同。

r latex modelsummary tinytable
1个回答
0
投票

如果您编织成 pdf,您可能会看到以下内容:

## Warning: To compile a LaTeX document with this table, the following commands must be placed in the document preamble:
## 
## \usepackage{tabularray}
## \usepackage{float}
## \usepackage{graphicx}
## \usepackage{codehigh}
## \usepackage[normalem]{ulem}
## \UseTblrLibrary{booktabs}
## \UseTblrLibrary{siunitx}
## \newcommand{\tinytableTabularrayUnderline}[1]{\underline{#1}}
## \newcommand{\tinytableTabularrayStrikeout}[1]{\sout{#1}}
## \NewTableCommand{\tinytableDefineColor}[3]{\definecolor{#1}{#2}{#3}}
## 
## To disable `siunitx` and prevent `modelsummary` from wrapping numeric entries in `\num{}`, call:
## 
## options("modelsummary_format_numeric_latex" = "plain")
##  This warning appears once per session.

因此,您的 OverLeaf 可能看起来像这样:

\documentclass{article}

\usepackage{tabularray}
\usepackage{float}
\usepackage{graphicx}
\usepackage{codehigh}
\usepackage[normalem]{ulem}
\UseTblrLibrary{booktabs}
\UseTblrLibrary{siunitx}
\newcommand{\tinytableTabularrayUnderline}[1]{\underline{#1}}
\newcommand{\tinytableTabularrayStrikeout}[1]{\sout{#1}}
\NewTableCommand{\tinytableDefineColor}[3]{\definecolor{#1}{#2}{#3}}

\begin{document}

\begin{table}
\centering
\begin{tblr}[         %% tabularray outer open
]                     %% tabularray outer close
{                     %% tabularray inner open
colspec={Q[]Q[]},
column{1}={halign=l,},
column{2}={halign=c,},
hline{6}={1,2}{solid, 0.05em, black},
}                     %% tabularray inner close
\toprule
& (1) \\ \midrule %% TinyTableHeader
(Intercept) & 0.010    \\
& (0.093)  \\
x           & 1.868    \\
& (0.086)  \\
Num.Obs.    & 100      \\
R2          & 0.827    \\
R2 Adj.     & 0.825    \\
AIC         & 272.5    \\
BIC         & 280.3    \\
Log.Lik.    & -133.254 \\
F           & 468.067  \\
RMSE        & 0.92     \\
\bottomrule
\end{tblr}
\end{table} 

\end{document}

© www.soinside.com 2019 - 2024. All rights reserved.