将 R 中的回归导出到 Latex - 十进制对齐

将 R 中的回归导出到 Latex - 十进制对齐

我使用 lm 函数在 R 中进行了回归分析。之后,我想使用以下代码将其导出到 Latex。

#export to Latex
texreg(list(model_cont,model_mag,model_pos), 
       digits = 4,  
       stars = c(0.01, 0.05, 0.1),
       custom.model.names = c("Delta", "Delta","Delta"),
       custom.coef.names = c("Intercept","FF","FG"),
       caption = "Contemporaneous regression results",
       label = "ContReg",
       caption.above = TRUE,
       siunitx = TRUE,
       booktabs = TRUE,
       use.packages = FALSE)

来自 R 的 Latex 代码如下:

\begin{table}
\caption{Contemporaneous regression results}
\begin{center}
\sisetup{parse-numbers=false, table-text-alignment=right}
\begin{tabular}{l S[table-format=4.7] S[table-format=4.6] S[table-format=4.7]}
\toprule
 & {Delta} & {Delta} & {Delta} \\
\midrule
Intercept       & 0.0001       & -0.0004^{*} & 0.0001        \\
                & (0.0001)     & (0.0002)    & (0.0001)      \\
FF              & 0.1234^{**}  & 0.4567^{*}  & -0.1237       \\
                & (0.3255)     & (0.2354)    & (0.2134)      \\
FG             & 0.1246^{***} & -0.6678     & 0.7788^{***}  \\
                & (0.1256)     & (0.3545)    & (0.4575)      \\
\midrule
R$^2$           & 0.5113       & 0.1150      & 0.5135        \\
Adj. R$^2$      & 0.4101       & 0.2124      & 0.9117        \\
Num. obs.       & 3888         & 3780        & 3394          \\
\bottomrule
\multicolumn{4}{l}{\scriptsize{$^{***}p<0.01$; $^{**}p<0.05$; $^{*}p<0.1$}}
\end{tabular}
\label{ContReg}
\end{center}
\end{table}

Latex 中生成的表格对齐了所有小数,对于观察值也是如此。但是,我不想对齐观察值的小数。有人能给我一些建议吗?

答案1

除了用Num. obs.花括号将行中的数字括起来之外,您可能还需要调整\sisetup指令的参数,以使表格“外观”更紧凑。

在此处输入图片描述

\documentclass{article}  % or some other suitable document class 
\usepackage{siunitx,booktabs}
\begin{document}
]\begin{table}
\sisetup{input-symbols = (), group-digits=false, 
         table-align-text-post = false}
\centering
\caption{Contemporaneous regression results\strut}\label{ContReg}
\begin{tabular}{@{} l *{3}{S[table-format=-1.7]} @{}}
\toprule
 & {Delta} & {Delta} & {Delta} \\
\midrule
Intercept       & 0.0001       & -0.0004*    & 0.0001        \\
                & (0.0001)     & (0.0002)    & (0.0001)      \\
FF              & 0.1234**     & 0.4567*     & -0.1237       \\
                & (0.3255)     & (0.2354)    & (0.2134)      \\
FG              & 0.1246***    & -0.6678     & 0.7788***     \\
                & (0.1256)     & (0.3545)    & (0.4575)      \\
\midrule
$R^2$           & 0.5113       & 0.1150      & 0.5135        \\
Adj.\ $R^2$     & 0.4101       & 0.2124      & 0.9117        \\
Num.\ obs.      & {3888}       & {3780}      & {3394}        \\
\bottomrule
\addlinespace
\multicolumn{4}{@{}l}{\footnotesize$^{***}p<0.01$; $^{**}p<0.05$; $^{*}p<0.1$}
\end{tabular}
\end{table}

\end{document}

相关内容