回归表对齐问题

回归表对齐问题

我对回归输出的对齐感到困扰 - 它并不完全适合表格线,如下所示:

任何帮助将不胜感激

\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{booktabs,multirow}
\usepackage{dcolumn}
\begin{document}

\begin{table}[htbp]\centering
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\caption{IV Analysis: Investment on Bribes table\label{tab1}}
\begin{tabular*}{0.8\hsize}{@{\hskip\tabcolsep\extracolsep\fill}l*{3}{D{.}{.}
{-1}}}
\toprule
                &\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}&\multicolumn{1}{c}{(3)}\\
                &\multicolumn{1}{c}{ln\_invest}&\multicolumn{1}{c}{ln\_invest}&\multicolumn{1}{c}{ln\_invest}\\
\midrule
Bribe &      -0.167         &     -0.0617         &     0.00939         \\
                &     (-0.90)         &     (-0.44)         &      (0.13)         \\
\addlinespace
medium(20-99)       &       0.339         &       0.298         &       1.024\sym{***}\\
                &      (0.90)         &      (0.73)         &      (8.74)         \\
\addlinespace
large(100 and over) &       2.426\sym{***}&       1.578\sym{**} &       2.654\sym{***}\\
                &      (4.31)         &      (2.79)         &     (17.07)         \\
\addlinespace
Govt=1              &       0.764         &       0.735         &      -0.112         \\
                &      (1.31)         &      (1.42)         &     (-0.63)         \\
\addlinespace
For=1               &      -0.341         &      -0.486         &       0.326\sym{*}  \\
                &     (-0.95)         &     (-1.41)         &      (2.14)         \\
\addlinespace
Obstacle            &       0.111         &      0.0340         &       0.114         \\
                &      (0.64)         &      (0.20)         &      (1.13)         \\
\addlinespace
Agree               &      -0.123         &     -0.0445         &      0.0196         \\
                &     (-0.66)         &     (-0.25)         &      (0.18)         \\
\addlinespace
lnAge               &       0.155         &       0.734\sym{**} &       0.122         \\
                &      (0.62)         &      (2.63)         &      (1.90)         \\
Constant            &       10.13\sym{***}&       8.684\sym{***}&       8.062\sym{***}\\
                &     (12.78)         &      (9.98)         &     (23.18)         \\
\midrule
Observations        &        6041         &        4724         &        1317         \\
\bottomrule
\multicolumn{4}{l}{\footnotesize \textit{t} statistics in parentheses}\\
\multicolumn{4}{l}{\footnotesize \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), 
\sym{***} \(p<0.001\)}\\
\multicolumn{4}{l}{\footnotesize Note: Robust standard errors in parentheses}\\
\end{tabular*}
\end{table}

\end{document}

桌子

答案1

作为使用threeparttablesiunitx包的练习。考虑的是表格的自然宽度(对我来说,它给出了更好的结果):

在此处输入图片描述

\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amsfonts,amssymb}
\usepackage{booktabs}

\usepackage{siunitx}                        % added
\usepackage{threeparttable}                 % added
%\newcommand\mc[1]{\multicolumn{1}{c}{#1}}  % not used now

\begin{document}
    \begin{table}[htb]
    \centering
\sisetup{table-number-alignment = center, % <-- added/changed
         table-space-text-pre ={(},
         table-space-text-post={\textsuperscript{***}},
         input-open-uncertainty={[},
         input-close-uncertainty={]},
         table-align-text-pre=false,
         table-align-text-post=false}
\begin{threeparttable}
    \caption{IV Analysis: Investment on Bribes table}
    \label{tab1}
\begin{tabular}{r 
                S[table-format=-2.3] % <-- adopted to number of digits in numbers in cells
                S[table-format=-1.4] % <-- adopted ...
                S[table-format=-1.5] % <-- adopted ...
                 }
\toprule
                    & \multicolumn{3}{c}{ln\_invest}                                \\
\cmidrule(lr){2-4}
                    &   {(1)}           &   {(2)}           &  {(3)}                \\
\midrule
Bribe               &  -0.167           &  -0.0617          &   0.00939             \\
                    & (-0.90)           & (-0.44)           &  (0.13)               \\
\addlinespace
medium (20-99)      &   0.339           &   0.298           &   1.024\tnote{***}    \\
                    &  (0.90)           &  (0.73)           &  (8.74)               \\
\addlinespace
large (100 and over)&   2.426\tnote{***}&   1.578\tnote{**} &   2.654\tnote{***}    \\
                    &  (4.31)           &  (2.79)           & (17.07)               \\
\addlinespace
Govt=1              &   0.764           &   0.735           &  -0.112               \\
                    &  (1.31)           &  (1.42)           & (-0.63)               \\
\addlinespace
For=1               &  -0.341           &  -0.486           &   0.326\tnote{*}      \\
                    & (-0.95)           & (-1.41)           &  (2.14)               \\
\addlinespace
Obstacle            &   0.111           &   0.0340          &   0.114               \\
                    &  (0.64)           &  (0.20)           &  (1.13)               \\
\addlinespace
Agree               &  -0.123           &  -0.0445          &   0.0196              \\
                    & (-0.66)           & (-0.25)           &  (0.18)               \\
\addlinespace
lnAge               &   0.155           &   0.734\tnote{**} &   0.122               \\
                    &  (0.62)           &  (2.63)           &  (1.90)               \\
\addlinespace
Constant            &  10.13\tnote{***} &   8.684\tnote{***}&   8.062\tnote{***}    \\
                    &  (12.78)          &  (9.98)           & (23.18)               \\
\midrule
Observations        & {6041}            & {4724}            & {1317}                \\
\bottomrule
\end{tabular}
    \smallskip
    \footnotesize
$t$ statistics in parentheses\par
\begin{tablenotes}[para,flushleft]
    \item[*]    $p < 0.10$,
    \item[**]   $p < 0.05$,
    \item[***]  $p < 0.01$
    \end{tablenotes}\par
Note: Robust standard errors in parentheses
\end{threeparttable}
    \end{table}
\end{document}

如果你坚持让表格宽度等于文本宽度,那么替换

\begin{tabular}{r ... }
...
\end{tabular}

\begin{tabular*}{\linewidth}{@{\hspace{\tabcolsep}\extracolsep{\fill}} r ...}
...
\end{tabular*}

编辑: 与此同时,我学到了(谢谢 海科·奥伯迪克, 看他的回答) 如何更好地定义列属性。考虑到这一点,我更改了列定义,参见\sisetup{...}上面的 MWE。现在,对于列标题的居中,\mc{...}不再需要该命令。

答案2

长度0.8\hsize错误:应该是\columnwidth

我做了其他一些更改;\sym宏在零宽度框中排版其参数,改善对齐;最后一行排版为居中条目,因为它们与其余列条目不匹配。

在注释中,\sym没有使用,而只是星号。

\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{booktabs}
\usepackage{dcolumn}
\begin{document}

\begin{table}[htbp]\centering
\newcommand\sym[1]{\rlap{$^{#1}$}}

\caption{IV Analysis: Investment on Bribes table\label{tab1}}

\begin{tabular*}{\columnwidth}{
  @{\hspace{\tabcolsep}\extracolsep{\fill}}
  l*{3}{D{.}{.}{-1}}
}
\toprule
  &\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}&\multicolumn{1}{c}{(3)}\\
  &\multicolumn{1}{c}{ln\_invest}&\multicolumn{1}{c}{ln\_invest}&\multicolumn{1}{c}{ln\_invest}\\
\midrule
Bribe                &  -0.167          &  -0.0617         &   0.00939        \\
                     & (-0.90)          & (-0.44)          &  (0.13)          \\
\addlinespace
medium (20-99)       &   0.339          &   0.298          &   1.024\sym{***} \\
                     &  (0.90)          &  (0.73)          &  (8.74)          \\
\addlinespace
large (100 and over) &   2.426\sym{***} &   1.578\sym{**}  &   2.654\sym{***} \\
                     &  (4.31)          &  (2.79)          & (17.07)          \\
\addlinespace
Govt=1               &   0.764          &   0.735          &  -0.112          \\
                     &  (1.31)          &  (1.42)          & (-0.63)          \\
\addlinespace
For=1                &  -0.341          &  -0.486          &   0.326\sym{*}   \\
                     & (-0.95)          & (-1.41)          &  (2.14)          \\
\addlinespace
Obstacle             &   0.111          &   0.0340         &   0.114          \\
                     &  (0.64)          &  (0.20)          &  (1.13)          \\
\addlinespace
Agree                &  -0.123          &  -0.0445         &   0.0196         \\
                     & (-0.66)          & (-0.25)          &  (0.18)          \\
\addlinespace
lnAge                &   0.155          &   0.734\sym{**}  &   0.122          \\
                     &  (0.62)          &  (2.63)          &  (1.90)          \\
Constant             &  10.13\sym{***}  &   8.684\sym{***} &   8.062\sym{***} \\
                     &  (12.78)         &  (9.98)          & (23.18)          \\
\midrule
Observations & \multicolumn{1}{c}{6041} & \multicolumn{1}{c}{4724} & \multicolumn{1}{c}{1317} \\
\bottomrule
\multicolumn{4}{l}{\footnotesize \textit{t} statistics in parentheses}\\
\multicolumn{4}{l}{\footnotesize * \(p<0.05\), ** \(p<0.01\), *** \(p<0.001\)}\\
\multicolumn{4}{l}{\footnotesize Note: Robust standard errors in parentheses}\\
\end{tabular*}
\end{table}

\end{document}

在此处输入图片描述

相关内容