[Tex/LaTex] Table alignment problem

horizontal alignmentsiunitxtables

So I wasn't happy with how esttab was formatting my regression tables from the statistical program Stata. So I instead I decided to attempt to build my own skeleton table, which had better formatting, but could easily be adjusted for different types of regression tables (e.g. fewer variables or fewer regressions etc). For a first attempt, it is quite good I think, but I have an alignment problem, which I am unsure how to fix.

\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}

enter image description here

Best Answer

You are padding too much data in the table. Anyway, here is an attempt.

\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}

enter image description here