在 1.37.1 版本(2020 年 5 月发布)中,texreg
引入了使用为此目的设计threeparttable
的 LaTeX 包的论点。threeparttable
示例 R 代码:
texreg(lm(speed ~ dist, data = cars),
custom.note = paste("\\item %stars. This regression",
"should be interpreted with strong",
"caution as it is likely plagued by",
"extensive omitted variable bias."),
single.row = TRUE,
threeparttable = TRUE)
输出:
\begin{table}
\begin{center}
\begin{threeparttable}
\begin{tabular}{l c}
\hline
& Model 1 \\
\hline
(Intercept) & $8.28 \; (0.87)^{***}$ \\
dist & $0.17 \; (0.02)^{***}$ \\
\hline
R$^2$ & $0.65$ \\
Adj. R$^2$ & $0.64$ \\
Num. obs. & $50$ \\
\hline
\end{tabular}
\begin{tablenotes}[flushleft]
\scriptsize{\item $^{***}p<0.001$; $^{**}p<0.01$; $^{*}p<0.05$. This regression should be interpreted with strong caution as it is likely plagued by extensive omitted variable bias}
\end{tablenotes}
\end{threeparttable}
\caption{Statistical models}
\label{table:coefficients}
\end{center}
\end{table}
呈现为:

请注意,自定义注释必须以\\item
. 也可以有多个项目和/或使用项目符号来格式化多个注释,例如在列表中:
texreg(lm(speed ~ dist, data = cars),
custom.note = paste("\\item[$\\bullet$] %stars.",
"\\item[$\\bullet$] This regression",
"should be interpreted with strong",
"caution as it is likely plagued by",
"extensive omitted variable bias."),
single.row = TRUE,
threeparttable = TRUE)
格式不完美,因为您无法设置所需的表格宽度;注释只是调整到相应表格的宽度。但我认为在一次显示多个模型并且某些系数名称比示例中长的实际使用场景中,这应该不是问题。此解决方案还支持longtable
环境,在这种情况下使用threeparttablex
包来代替。
这是一个示例,说明如何使用两个模型使其看起来不错:
fit <- lm(speed ~ dist, data = cars)
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)
这产生:
\begin{table}
\begin{center}
\begin{threeparttable}
\begin{tabular}{l c c}
\hline
& Model 1 & Model 2 \\
\hline
(Intercept) & $8.28 \; (0.87)^{***}$ & $8.28 \; (0.87)^{***}$ \\
dist & $0.17 \; (0.02)^{***}$ & $0.17 \; (0.02)^{***}$ \\
\hline
R$^2$ & $0.65$ & $0.65$ \\
Adj. R$^2$ & $0.64$ & $0.64$ \\
Num. obs. & $50$ & $50$ \\
\hline
\end{tabular}
\begin{tablenotes}[flushleft]
\scriptsize{\item[\hspace{-5mm}] $^{***}p<0.001$; $^{**}p<0.01$; $^{*}p<0.05$. \item[\hspace{-5mm}] This regression should be interpreted with strong caution as it is likely plagued by extensive omitted variable bias.}
\end{tablenotes}
\end{threeparttable}
\caption{Statistical models}
\label{table:coefficients}
\end{center}
\end{table}
呈现为:
