2

I am building tables for a paper I am writing and I am stuck with issues about aligning the contents of columns. I am using the code below to obtain the table I need and the purpose is that all the content should be vertically aligned. The problem is that I get something like this in the last panel: enter image description here

Mean row is totally misaligned and I can't understand why. Please any hint is valuable

\documentclass{article}
    \usepackage[utf8]{inputenc}
    \usepackage{rotating}
    \usepackage{booktabs,tabularx,dcolumn,adjustbox}
    \usepackage[flushleft]{threeparttable}
    \newcolumntype{C}{>{\centering\arraybackslash}X}
    \newcolumntype{d}[1]{D..{#1}}
    \usepackage[font=large,skip=.333\baselineskip]{caption}
    \usepackage[margin=0.5in]{geometry}

\newcommand\mc[1]{\multicolumn{1}{c}{#1}}
\newcommand\mC[1]{\multicolumn{1}{c}{\begin{tabular}[t]{@{}c@{}}#1\end{tabular}}}
\newcommand\ic[1]{\multicolumn{1}{D..{6.2}}{#1}}
\newcommand\pc[1]{\multicolumn{1}{D..{0.1}}{#1}}

\begin{document}
\begin{center}
\rotatebox{90}{
\begin{threeparttable}
\captionof{table}{Marriage market outcomes}
        \begin{tabular}{@{} l *{11}{d{2.5}} @{}} 
            \toprule\toprule
            & \mc{(1)} & \mc{(2)} & \mc{(3)} & \mc{(4)} & \mc{(5)} & \mc{(6)} & \mc{(7)} & \mc{(8)} & \mc{(9)}& \mc{(10)}  \\                   \midrule
            \addlinespace
            Outcome & \mC{Marriage \\age} 
            & \mC{Age at\\ first birth} 
            & \mC{Number of\\ living children}
            & \mC{Ideal number\\ of boys}
            & \mC{Ideal number \\of girls}
            & \mC{Husband's\\ age}
            & \mC{Husband's \\schooling}
            & \mC{Husband \\employed}
            & \mC{Age \\difference}
            & \mC{Schooling\\ difference}
            \\ 
            \midrule
            \multicolumn{11}{c}{\textbf{Panel A: OLS with optimal bandwidth $\hat{h}$}} \\
            \midrule
            Years of school & 0.307^{***}  & 0.274^{***}  & -0.104^{***} & -0.034^{***} & -0.047^{***}& -0.172^{***}& 0.502^{***} & 0.002 & -0.168^{***} & -0.499^{***} \\
             & (0.023)^{\dag\dag\dag}  & (0.020)^{\dag\dag\dag}  & (0.009)^{\dag\dag\dag}  & (0.007)^{\dag\dag\dag}   & (0.007)^{\dag\dag\dag} &(0.003)^{\dag\dag\dag}& (0.028)^{\dag\dag\dag}   & (0.002) & (0.002)^{\dag\dag\dag}&  (0.046)^{\dag\dag\dag} \\ 
            \addlinespace\midrule
            \multicolumn{11}{c}{\textbf{Panel B: Reduced form with optimal bandwidth $\hat{h}$}} \\
            \midrule
            Treatment & 0.214& -0.208 & -0.014 & 0.026 & -0.075 & 0.125& 0.677 & 0.051^{**} & 0.168 & 0.371\\
            & (0.294) & (0.297)& (0.099)& (0.072) & (0.083) &(0.407)   & (0.552)&(0.022)^{\dag\dag}& (0.031)& (0.555) \\ 
            \addlinespace\midrule
            \multicolumn{11}{c}{\textbf{Panel C: IV with optimal bandwidth $\hat{h}$}} \\
            \midrule
            Years of school& 0.933 & -0.725 & -0.110  & 0.174  & -0.638& 0.361 & 2.713 & 0.554&0.057& 0.490\\
            & (1.278)  & (1.490)& (0.653) & (0.610) & (1.464)& (1.559) & (3.049)  & (1.842)& (0.039) & (1.602) \\ 
            \addlinespace\midrule\midrule
            Mean& \pc{0.71}& \pc{18.5}& \pc{2.6}& \pc{1.6}& \pc{1.7} & \pc{32.1} & \pc{7.7}& \pc{0.93}& \pc{5.4} & \pc{1.3}\\
            Bandwidth & \ic{42} & \ic{41} & \ic{34} & \ic{36} & \ic{33} & \ic{41}& \ic{44}& \ic{44}& \ic{34}& \ic{30}\\ 
            Obs & \ic{ 1,603 } & \ic{1,539}& \ic{1,287}& \ic{1,637} & \ic{1,353}& \ic{1,100}& \ic{1,331}& \ic{1,470}&\ic{1,128}& \ic{973}\\
            \bottomrule \bottomrule\addlinespace
            \multicolumn{11}{c}{ $^{***}\ p<0.01$; $^{**}\ p<0.05$; $^{*}\  p<0.1$} \\
        \end{tabular}
\begin {tablenotes}
\small
\item \textbf{Notes}:
\end{tablenotes}
\end{threeparttable}
}
\end{center}
\end{document}
2
  • You have Mean& \pc{0.71}& \ic{18.5}& instead of Mean& \pc{0.71}& \pc{18.5}& but it's not clear the exact alignment you desire: it should take into account of the decimal digits?
    – CarLaTeX
    Jul 13, 2017 at 11:03
  • @CarLaTeX Sorry, this was a mistake. I'd like to have all columns as the first one. I don't need decimal to be taken into account.
    – PhDing
    Jul 13, 2017 at 13:24

2 Answers 2

1

Some suggestions:

  • The material in the final three rows looks like there's no natural way to align the numbers in each column in a compelling way across rows. E.g., if you were to right-align the last two rows, you'd actually risk creating a rather misleading impression, about the bandwidth parameter and the number of observations somehow being related to each other (other than the fact that they're both integer-valued). I would \mc directives to simply center them.

  • Since you're loading the rotating package, you might as well make use of the package's sidewaystable environment.

enter image description here

\documentclass{article}
    \usepackage[utf8]{inputenc}
    \usepackage{rotating}
    \usepackage{booktabs,tabularx,dcolumn}
    \usepackage[flushleft]{threeparttable}
    \newcolumntype{C}{>{\centering\arraybackslash}X}
    \newcolumntype{d}[1]{D..{#1}}
    \usepackage[font=large,skip=.333\baselineskip]{caption}
    \usepackage[margin=0.5in]{geometry}

\newcommand\mc[1]{\multicolumn{1}{c}{#1}}
\newcommand\mC[1]{\multicolumn{1}{c}{%
     \begin{tabular}[t]{@{}c@{}}#1\end{tabular}}}

\begin{document}
\begin{sidewaystable}
\centering
\begin{threeparttable}
\caption{Marriage market outcomes}
\begin{tabular}{@{} l *{10}{d{2.5}} @{}} 
\toprule
        & \mc{(1)} & \mc{(2)} & \mc{(3)} & \mc{(4)} & \mc{(5)} 
        & \mc{(6)} & \mc{(7)} & \mc{(8)} & \mc{(9)} & \mc{(10)}  \\                   
\midrule
\addlinespace
Outcome & \mC{Marriage \\age}              & \mC{Age at\\ first birth} 
        & \mC{Number of\\ living children} & \mC{Ideal number\\ of boys} 
        & \mC{Ideal number \\of girls}     & \mC{Husband's\\ age}
        & \mC{Husband's \\schooling}       & \mC{Husband \\employed}
        & \mC{Age \\difference}            & \mC{Schooling\\ difference}  \\ 
\midrule
\addlinespace
\multicolumn{11}{c}{\textbf{Panel A: OLS with optimal bandwidth $\hat{h}$}} \\
\addlinespace
\midrule
Years of school & 0.307^{***}  & 0.274^{***}  & -0.104^{***} & -0.034^{***} 
                & -0.047^{***} & -0.172^{***} & 0.502^{***}  & 0.002        
                & -0.168^{***} & -0.499^{***} \\
                & (0.023)^{\dag\dag\dag}  & (0.020)^{\dag\dag\dag} 
                & (0.009)^{\dag\dag\dag}  & (0.007)^{\dag\dag\dag}   
                & (0.007)^{\dag\dag\dag}  & (0.003)^{\dag\dag\dag}
                & (0.028)^{\dag\dag\dag}  & (0.002) 
                & (0.002)^{\dag\dag\dag}  & (0.046)^{\dag\dag\dag} \\ 

\midrule
\addlinespace
\multicolumn{11}{c}{\textbf{Panel B: Reduced form with optimal bandwidth $\hat{h}$}} \\
\addlinespace
\midrule
Treatment       &  0.214 & -0.208     & -0.014     & 0.026   & -0.075 
                & 0.125  & 0.677      & 0.051^{**} & 0.168   & 0.371\\
                & (0.294)& (0.297)    & (0.099)    & (0.072) & (0.083) 
                & (0.407)& (0.552)    &(0.022)^{\dag\dag}& (0.031)& (0.555) \\ 
\midrule
\addlinespace
\multicolumn{11}{c}{\textbf{Panel C: IV with optimal bandwidth $\hat{h}$}} \\
\addlinespace
\midrule
Years of school & 0.933 & -0.725 & -0.110  & 0.174  & -0.638
                & 0.361 & 2.713  & 0.554   &0.057   & 0.490\\
                & (1.278)& (1.490)& (0.653)& (0.610)& (1.464)
                & (1.559) & (3.049)  & (1.842)& (0.039) & (1.602) \\ 
\addlinespace
\midrule
\addlinespace
Mean            & \mc{0.71} & \mc{18.5}& \mc{2.6} & \mc{1.6 }& \mc{1.7} 
                & \mc{32.1} & \mc{7.7} & \mc{0.93}& \mc{5.4} & \mc{1.3}\\
Bandwidth       & \mc{42} & \mc{41} & \mc{34} & \mc{36} & \mc{33} 
                & \mc{41} & \mc{44} & \mc{44} & \mc{34} & \mc{30}\\ 
Obs.            & \mc{1,603} & \mc{1,539} & \mc{1,287} & \mc{1,637} & \mc{1,353}
                & \mc{1,100} & \mc{1,331} & \mc{1,470} & \mc{1,128} & \mc{973}\\
\bottomrule
\addlinespace
\multicolumn{11}{c}{ $^{***}\ p<0.01$; $^{**}\ p<0.05$; $^{*}\  p<0.1$} \\
\end{tabular}
\begin{tablenotes}
\small
\item\textbf{Notes}: \dots
\end{tablenotes}
\end{threeparttable}
\end{sidewaystable}
\end{document}
1

I'm not sure this is the alignment you desire (nor this is the best way to do it):

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{rotating}
\usepackage{booktabs,tabularx,dcolumn,adjustbox}
\usepackage[flushleft]{threeparttable}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\newcolumntype{d}[1]{D..{#1}}
\usepackage[font=large,skip=.333\baselineskip]{caption}
\usepackage[margin=0.5in]{geometry}

\newcommand\mc[1]{\multicolumn{1}{c}{#1}}
\newcommand\mC[1]{\multicolumn{1}{c}{\begin{tabular}[t]{@{}c@{}}#1\end{tabular}}}
\newcommand\ic[1]{\multicolumn{1}{D..{6.2}}{#1}}
\newcommand\pc[1]{\multicolumn{1}{D..{4.5}}{#1}}


\begin{document}
    \begin{center}
        \rotatebox{90}{
            \begin{threeparttable}
                \captionof{table}{Marriage market outcomes}
                \begin{tabular}{@{} l *{11}{d{2.5}} @{}} 
                    \toprule\toprule
                    & \mc{(1)} & \mc{(2)} & \mc{(3)} & \mc{(4)} & \mc{(5)} & \mc{(6)} & \mc{(7)} & \mc{(8)} & \mc{(9)}& \mc{(10)}  \\                   \midrule
                    \addlinespace
                    Outcome & \mC{Marriage \\age} 
                    & \mC{Age at\\ first birth} 
                    & \mC{Number of\\ living children}
                    & \mC{Ideal number\\ of boys}
                    & \mC{Ideal number \\of girls}
                    & \mC{Husband's\\ age}
                    & \mC{Husband's \\schooling}
                    & \mC{Husband \\employed}
                    & \mC{Age \\difference}
                    & \mC{Schooling\\ difference}
                    \\ 
                    \midrule
                    \multicolumn{11}{c}{\textbf{Panel A: OLS with optimal bandwidth $\hat{h}$}} \\
                    \midrule
                    Years of school & 0.307^{***}  & 0.274^{***}  & -0.104^{***} & -0.034^{***} & -0.047^{***}& -0.172^{***}& 0.502^{***} & 0.002 & -0.168^{***} & -0.499^{***} \\
                    & (0.023)^{\dag\dag\dag}  & (0.020)^{\dag\dag\dag}  & (0.009)^{\dag\dag\dag}  & (0.007)^{\dag\dag\dag}   & (0.007)^{\dag\dag\dag} &(0.003)^{\dag\dag\dag}& (0.028)^{\dag\dag\dag}   & (0.002) & (0.002)^{\dag\dag\dag}&  (0.046)^{\dag\dag\dag} \\ 
                    \addlinespace\midrule
                    \multicolumn{11}{c}{\textbf{Panel B: Reduced form with optimal bandwidth $\hat{h}$}} \\
                    \midrule
                    Treatment & 0.214& -0.208 & -0.014 & 0.026 & -0.075 & 0.125& 0.677 & 0.051^{**} & 0.168 & 0.371\\
                    & (0.294) & (0.297)& (0.099)& (0.072) & (0.083) &(0.407)   & (0.552)&(0.022)^{\dag\dag}& (0.031)& (0.555) \\ 
                    \addlinespace\midrule
                    \multicolumn{11}{c}{\textbf{Panel C: IV with optimal bandwidth $\hat{h}$}} \\
                    \midrule
                    Years of school& 0.933 & -0.725 & -0.110  & 0.174  & -0.638& 0.361 & 2.713 & 0.554&0.057& 0.490\\
                    & (1.278)  & (1.490)& (0.653) & (0.610) & (1.464)& (1.559) & (3.049)  & (1.842)& (0.039) & (1.602) \\ 
                    \addlinespace\midrule\midrule
                    Mean& \pc{0.71}& \pc{18.50}& \pc{2.60}& \pc{1.60}& \pc{1.70} & \pc{32.10} & \pc{7.70}& \pc{0.93}& \pc{5.40} & \pc{1.30}\\
                    Bandwidth & \ic{42} & \ic{41} & \ic{34} & \ic{36} & \ic{33} & \ic{41}& \ic{44}& \ic{44}& \ic{34}& \ic{30}\\ 
                    Obs & \ic{ 1,603 } & \ic{1,539}& \ic{1,287}& \ic{1,637} & \ic{1,353}& \ic{1,100}& \ic{1,331}& \ic{1,470}&\ic{1,128}& \ic{973}\\
                    \bottomrule \bottomrule\addlinespace
                    \multicolumn{11}{c}{ $^{***}\ p<0.01$; $^{**}\ p<0.05$; $^{*}\  p<0.1$} \\
                \end{tabular}
                \begin {tablenotes}
                \small
                \item \textbf{Notes}:
            \end{tablenotes}
        \end{threeparttable}
    }
\end{center}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .