表格环境中的垂直对齐问题

表格环境中的垂直对齐问题

我正在为正在撰写的论文构建表格,但在对齐列内容方面遇到了问题。我使用下面的代码来获取我需要的表格,目的是使所有内容都垂直对齐。问题是我在最后一个面板中得到了类似这样的结果: 在此处输入图片描述

平均行完全错位,我不明白为什么。请提供任何有价值的提示

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

答案1

一些建议:

  • 最后三行的内容看起来似乎没有自然的方法以令人信服的方式跨行对齐每列中的数字。例如,如果您要右对齐最后两行,您实际上可能会产生一种相当误导性的印象,即带宽参数和观察次数以某种方式相互关联(除了它们都是整数值这一事实之外)。我会\mc指示简单地中心他们。

  • 既然您正在加载rotating包,那么您不妨利用包的sidewaystable环境。

在此处输入图片描述

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

答案2

我不确定这是你想要的对齐方式(这也不是最好的方法):

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

在此处输入图片描述

相关内容