表格对齐问题

表格对齐问题

所以我对统计程序 Stata 中回归表的格式不满意esttab。所以我决定尝试构建自己的骨架表,该表格式更好,但可以轻松调整为不同类型的回归表(例如更少的变量或更少的回归等)。作为第一次尝试,我认为它相当不错,但我有一个对齐问题,我不知道如何解决。

\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}
\sisetup{input-symbols = {()}}
\begin{document}
\begin{table}[H]
\caption{Regression Results}
\label{table:RegressionResults}
\begin{tabular*}{\textwidth}{
!{\extracolsep{\fill}}
l
*{6}{S[table-format=2.3, table-align-text-post=false]}
}
\toprule
{\bfseries Variable} & {\bfseries All} & {\bfseries Commerce} & {\bfseries B.Bus.Sci} &     {\bfseries BCom} & {\bfseries EBE} & {\bfseries Science} \\
\midrule
Gender & 1.953*** & 1.711*** & 1.626*** & 1.617*** & 1.005 & 1.793*** \\ 
 & (0.137) & (0.194) & (0.269) & (0.269) & (0.162) & (0.253) \\ 
Age & 1.010 & 0.920 & 0.761*** & 1.288** & 1.066 & 1.072 \\ 
 & (0.039) & (0.065) & (0.071) & (0.160) & (0.080) & (0.075) \\ 
Coloured & 1.099 & 1.122 & 1.482 & 0.774 & 1.048 & 1.276 \\ 
 & (0.186) & (0.327) & (0.600) & (0.340) & (0.354) & (0.461) \\ 
Indian/Asian & 0.670** & 0.488** & 1.021 & 0.337*** & 0.565* & 0.947 \\ 
 & (0.114) & (0.137) & (0.443) & (0.137) & (0.187) & (0.384) \\ 
White & 5.123*** & 2.953*** & 3.510*** & 2.679** & 4.748*** & 12.548*** \\ 
 & (0.841) & (0.817) & (1.361) & (1.112) & (1.465) & (4.620) \\ 
Financial Aid & 0.678*** & 0.397*** & 0.420*** & 0.400*** & 0.754* & 0.706** \\ 
 & (0.056) & (0.054) & (0.077) & (0.081) & (0.129) & (0.118) \\ 
Academic Development & 0.911 & 0.930 & 1.116 & 0.783 & 0.897 & 0.574*** \\ 
 & (0.083) & (0.132) & (0.211) & (0.175) & (0.184) & (0.124) \\ 
English Home Language & 1.401** & 1.716** & 1.472 & 2.265** & 1.739* & 1.293 \\ 
 & (0.208) & (0.433) & (0.512) & (0.864) & (0.493) & (0.418) \\ 
Quintile 1 & 1.016 & 1.051 & 1.250 & 0.516 & 0.794 & 1.469 \\ 
 & (0.244) & (0.456) & (0.610) & (0.783) & (0.375) & (0.627) \\ 
Quintile 2 & 1.291 & 1.161 & 0.966 & 1.653 & 1.846* & 0.968 \\ 
 & (0.242) & (0.449) & (0.455) & (1.175) & (0.634) & (0.307) \\ 
Quintile 4 & 0.920 & 0.771 & 0.818 & 0.559 & 0.827 & 0.744 \\ 
 & (0.140) & (0.211) & (0.276) & (0.287) & (0.252) & (0.206) \\ 
Quintile 5 & 1.760*** & 1.351 & 1.412 & 1.616 & 1.845** & 1.527* \\ 
 & (0.218) & (0.301) & (0.390) & (0.687) & (0.465) & (0.362) \\ 
Independent & 1.663*** & 1.203 & 1.312 & 1.626 & 1.789** & 1.335 \\ 
 & (0.219) & (0.284) & (0.399) & (0.708) & (0.472) & (0.338) \\ 
Western Cape & 1.145 & 1.275* & 1.144 & 1.661** & 1.073 & 0.950 \\ 
 & (0.099) & (0.183) & (0.235) & (0.358) & (0.192) & (0.167) \\ 
High School GPA & 1.119*** & 1.119*** & 1.156*** & 1.111*** & 1.148*** & 1.134*** \\ 
 & (0.007) & (0.011) & (0.017) & (0.016) & (0.014) & (0.014) \\ 
Mathematics & 1.007** & 1.012** & 1.005 & 1.048*** & 1.054*** & 1.022*** \\ 
 & (0.003) & (0.006) & (0.008) & (0.009) & (0.008) & (0.006) \\ 
English & 1.013*** & 1.012 & 1.006 & 1.038*** & 1.007 & 1.003 \\ 
 & (0.004) & (0.008) & (0.011) & (0.012) & (0.009) & (0.008) \\ 
Science & 0.698*** & 1.053 & 1.352* & 1.239 &  & 1.252 \\ 
 & (0.074) & (0.136) & (0.233) & (0.255) &  & (0.557) \\ 
Residence & 1.117 & 1.401** & 1.240 & 1.061 & 1.019 & 0.937 \\ 
\midrule
Observations & {36 333} & {20 409}  &{7 408}    & {13 001}  & {9 169}&  {6 755} \\
Pseudo \(R^{2}\) & {0.397} & {0.451} & {0.420} & {0.574} & {0.419} & {0.431} \\
\bottomrule
{\footnotesize Standard errors in parentheses}\\
{\footnotesize * \(p<0.05\), ** \(p<0.01\), *** \(p<0.001\)}\\
\end{tabular*}
\end{table}
\end{document}

在此处输入图片描述

答案1

您在表中填充了太多数据。无论如何,这是一次尝试。

\documentclass{article}
\usepackage{booktabs,multirow}
\usepackage{siunitx}
\sisetup{detect-mode,
        group-digits    = false,
        input-symbols   = ( ) }

\newcommand{\level}[1]{%
\multirow{2}{*}{%
  \begin{tabular}{@{}>{\raggedright\arraybackslash}p{0.2\textwidth}@{}}
  \strut#1\strut
  \end{tabular}%
  }
  }

\begin{document}
\begin{table}[htb]
\caption{Regression Results}
\label{table:RegressionResults}
\centering
\begin{tabular}{
l
*{6}{S[table-format=2.5, table-align-text-post=false]}
}
\toprule
{\bfseries\small Variable} & {\bfseries\small All} & {\bfseries\small Commerce} & {\bfseries\small B.Bus.Sci} &     {\bfseries\small BCom} & {\bfseries\small EBE} & {\bfseries\small Science} \\
\midrule
\level{Gender} & 1.953*** & 1.711*** & 1.626*** & 1.617*** & 1.005 & 1.793*** \\
 & (0.137) & (0.194) & (0.269) & (0.269) & (0.162) & (0.253) \\
\level{Age} & 1.010 & 0.920 & 0.761*** & 1.288** & 1.066 & 1.072 \\
 & (0.039) & (0.065) & (0.071) & (0.160) & (0.080) & (0.075) \\
\level{Coloured} & 1.099 & 1.122 & 1.482 & 0.774 & 1.048 & 1.276 \\
 & (0.186) & (0.327) & (0.600) & (0.340) & (0.354) & (0.461) \\
\level{Indian/Asian} & 0.670** & 0.488** & 1.021 & 0.337*** & 0.565* & 0.947 \\
 & (0.114) & (0.137) & (0.443) & (0.137) & (0.187) & (0.384) \\
\level{White} & 5.123*** & 2.953*** & 3.510*** & 2.679** & 4.748*** & 12.548*** \\
 & (0.841) & (0.817) & (1.361) & (1.112) & (1.465) & (4.620) \\
\level{Financial Aid} & 0.678*** & 0.397*** & 0.420*** & 0.400*** & 0.754* & 0.706** \\
 & (0.056) & (0.054) & (0.077) & (0.081) & (0.129) & (0.118) \\
\level{Academic Development} & 0.911 & 0.930 & 1.116 & 0.783 & 0.897 & 0.574*** \\
 & (0.083) & (0.132) & (0.211) & (0.175) & (0.184) & (0.124) \\
\level{English Home Language} & 1.401** & 1.716** & 1.472 & 2.265** & 1.739* & 1.293 \\
 & (0.208) & (0.433) & (0.512) & (0.864) & (0.493) & (0.418) \\
\level{Quintile 1} & 1.016 & 1.051 & 1.250 & 0.516 & 0.794 & 1.469 \\
 & (0.244) & (0.456) & (0.610) & (0.783) & (0.375) & (0.627) \\
\level{Quintile 2} & 1.291 & 1.161 & 0.966 & 1.653 & 1.846* & 0.968 \\
 & (0.242) & (0.449) & (0.455) & (1.175) & (0.634) & (0.307) \\
\level{Quintile 4} & 0.920 & 0.771 & 0.818 & 0.559 & 0.827 & 0.744 \\
 & (0.140) & (0.211) & (0.276) & (0.287) & (0.252) & (0.206) \\
\level{Quintile 5} & 1.760*** & 1.351 & 1.412 & 1.616 & 1.845** & 1.527* \\
 & (0.218) & (0.301) & (0.390) & (0.687) & (0.465) & (0.362) \\
\level{Independent} & 1.663*** & 1.203 & 1.312 & 1.626 & 1.789** & 1.335 \\
 & (0.219) & (0.284) & (0.399) & (0.708) & (0.472) & (0.338) \\
\level{Western Cape} & 1.145 & 1.275* & 1.144 & 1.661** & 1.073 & 0.950 \\
 & (0.099) & (0.183) & (0.235) & (0.358) & (0.192) & (0.167) \\
\level{High School GPA} & 1.119*** & 1.119*** & 1.156*** & 1.111*** & 1.148*** & 1.134*** \\
 & (0.007) & (0.011) & (0.017) & (0.016) & (0.014) & (0.014) \\
\level{Mathematics} & 1.007** & 1.012** & 1.005 & 1.048*** & 1.054*** & 1.022*** \\
 & (0.003) & (0.006) & (0.008) & (0.009) & (0.008) & (0.006) \\
\level{English} & 1.013*** & 1.012 & 1.006 & 1.038*** & 1.007 & 1.003 \\
 & (0.004) & (0.008) & (0.011) & (0.012) & (0.009) & (0.008) \\
\level{Science} & 0.698*** & 1.053 & 1.352* & 1.239 &  & 1.252 \\
 & (0.074) & (0.136) & (0.233) & (0.255) &  & (0.557) \\
Residence & 1.117 & 1.401** & 1.240 & 1.061 & 1.019 & 0.937 \\
\midrule
Observations & {36 333} & {20 409}  &{7 408}    & {13 001}  & {9 169}&  {6 755} \\
Pseudo \(R^{2}\) & {0.397} & {0.451} & {0.420} & {0.574} & {0.419} & {0.431} \\
\bottomrule
\multicolumn{7}{l}{\footnotesize Standard errors in parentheses}\\
\multicolumn{7}{l}{\footnotesize * \(p<0.05\), ** \(p<0.01\), *** \(p<0.001\)}\\
\end{tabular}
\end{table}
\end{document}

在此处输入图片描述

答案2

dcolumn这是一个使用包及其d列类型而不是siunitx包及其列类型的解决方案S。我认为使用该dcolumn包的主要优点是它简化了在上标位置设置单、双和三星号的过程;这样做不仅在风格上令人愉悦,而且还有助于节省此表中急需的空间。

另外,我不会将标题行中的单词加粗。恕我直言,在这种情况下使用粗体字近乎粗俗,而且肯定不会增加表格的可读性或可理解性。

通过这些建议的改变和减少列间空白参数\tabcolsep到 1.5 pt,您可以使表格适合文本块的宽度没有必须减小字体大小。

顺便说一句,表格底部附近似乎缺少一行标准误差。

在此处输入图片描述

\documentclass{article}
\usepackage{booktabs,dcolumn}
\newcolumntype{d}[1]{D{.}{.}{#1}}
\newcommand\mc[1]{\multicolumn{1}{c}{#1}} % handy shortcut macro
\begin{document}
\begin{table}
\setlength\tabcolsep{1.5pt} % default value: 6pt
\caption{Regression Results}
\label{table:RegressionResults}
\begin{tabular*}{\textwidth}{%
   @{} l @{\extracolsep{\fill}} *{5}{d{2.5}} d{2.6} @{}}
\toprule
Variable & \mc{All} & \mc{Comm.} & \mc{B.Bus.Sci} & \mc{BCom} & \mc{EBE} & \mc{Science} \\
\midrule
Gender & 1.953^{***} & 1.711^{***} & 1.626^{***} & 1.617^{***} & 1.005 & 1.793^{***} \\
       & (0.137) & (0.194) & (0.269) & (0.269) & (0.162) & (0.253) \\
Age & 1.010 & 0.920 & 0.761^{***} & 1.288^{**} & 1.066 & 1.072 \\
    & (0.039) & (0.065) & (0.071) & (0.160) & (0.080) & (0.075) \\
Coloured & 1.099 & 1.122 & 1.482 & 0.774 & 1.048 & 1.276 \\
         & (0.186) & (0.327) & (0.600) & (0.340) & (0.354) & (0.461) \\
Indian/Asian & 0.670^{**} & 0.488^{**} & 1.021 & 0.337^{***} & 0.565^{*} & 0.947 \\
             & (0.114) & (0.137) & (0.443) & (0.137) & (0.187) & (0.384) \\
White & 5.123^{***} & 2.953^{***} & 3.510^{***} & 2.679^{**} & 4.748^{***} & 12.548^{***} \\
      & (0.841) & (0.817) & (1.361) & (1.112) & (1.465) & (4.620) \\
Financial Aid & 0.678^{***} & 0.397^{***} & 0.420^{***} & 0.400^{***} & 0.754^{*} & 0.706^{**} \\
              & (0.056) & (0.054) & (0.077) & (0.081) & (0.129) & (0.118) \\
Academic Develop. & 0.911 & 0.930 & 1.116 & 0.783 & 0.897 & 0.574^{***} \\
                  & (0.083) & (0.132) & (0.211) & (0.175) & (0.184) & (0.124) \\
English Home Lang. & 1.401^{**} & 1.716^{**} & 1.472 & 2.265^{**} & 1.739^{*} & 1.293 \\
                   & (0.208) & (0.433) & (0.512) & (0.864) & (0.493) & (0.418) \\
Quintile 1 & 1.016 & 1.051 & 1.250 & 0.516 & 0.794 & 1.469 \\
           & (0.244) & (0.456) & (0.610) & (0.783) & (0.375) & (0.627) \\
Quintile 2 & 1.291 & 1.161 & 0.966 & 1.653 & 1.846^{*} & 0.968 \\
           & (0.242) & (0.449) & (0.455) & (1.175) & (0.634) & (0.307) \\
Quintile 4 & 0.920 & 0.771 & 0.818 & 0.559 & 0.827 & 0.744 \\
           & (0.140) & (0.211) & (0.276) & (0.287) & (0.252) & (0.206) \\
Quintile 5 & 1.760^{***} & 1.351 & 1.412 & 1.616 & 1.845^{**} & 1.527^{*} \\
           & (0.218) & (0.301) & (0.390) & (0.687) & (0.465) & (0.362) \\
Independent & 1.663^{***} & 1.203 & 1.312 & 1.626 & 1.789^{**} & 1.335 \\
            & (0.219) & (0.284) & (0.399) & (0.708) & (0.472) & (0.338) \\
Western Cape & 1.145 & 1.275^{*} & 1.144 & 1.661^{**} & 1.073 & 0.950 \\
             & (0.099) & (0.183) & (0.235) & (0.358) & (0.192) & (0.167) \\
High School GPA & 1.119^{***} & 1.119^{***} & 1.156^{***} & 1.111^{***} & 1.148^{***} & 1.134^{***} \\
                & (0.007) & (0.011) & (0.017) & (0.016) & (0.014) & (0.014) \\
Mathematics & 1.007^{**} & 1.012^{**} & 1.005 & 1.048^{***} & 1.054^{***} & 1.022^{***} \\
            & (0.003) & (0.006) & (0.008) & (0.009) & (0.008) & (0.006) \\
English & 1.013^{***} & 1.012 & 1.006 & 1.038^{***} & 1.007 & 1.003 \\
        & (0.004) & (0.008) & (0.011) & (0.012) & (0.009) & (0.008) \\
Science & 0.698^{***} & 1.053 & 1.352^{*} & 1.239 &  & 1.252 \\
        & (0.074) & (0.136) & (0.233) & (0.255) &  & (0.557) \\
Residence & 1.117 & 1.401^{**} & 1.240 & 1.061 & 1.019 & 0.937 \\
\midrule
Observations & \mc{36333} & \mc{20409} & \mc{7408} & \mc{13001} & \mc{9169} & \mc{6755} \\
Pseudo \(R^{2}\) & \mc{0.397} & \mc{0.451} & \mc{0.420} & \mc{0.574} & \mc{0.419} & \mc{0.431} \\
\midrule[\heavyrulewidth]
\multicolumn{7}{@{}l}{\footnotesize Standard errors in parentheses}\\
\multicolumn{7}{@{}l}{\footnotesize ${}^{*}$ \(p<0.05\), ${}^{**}$ \(p<0.01\), ${}^{***}$ \(p<0.001\)}\\
\end{tabular*}
\end{table}
\end{document}

相关内容