列居中问题

列居中问题

我遇到了一个我真的无法理解的问题。我试图让每列中的所有数字居中,但它只适用于每个面板的前两行(治疗和后续行),而不适用于其他两行(带宽和观测值)。有什么提示吗?

这是我的代码:

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

\newcommand\mc[1]{\multicolumn{1}{c}{#1}}
\newcommand\mC[1]{\multicolumn{1}{C}{#1}}

\begin{document}

\begin{table}[t]
\caption{Reduced form regressions for labour market outcomes}
\begin{tabularx}{\textwidth}{@{} l *{7}{d{2.5}} cc @{}} 
\toprule
 & \mc{(1)} & \mc{(2)} & \mc{(3)} & \mc{(4)} & \mc{(5)} & \mc{(6)} & \mc{(7)} \\
\addlinespace
Outcome & \mC{Employed} 
        & \mC{Agricultural Job} 
        & \mC{Non Agric. Job}
        & \mC{Service Job}
        & \mC{Occasionally Employed}
        & \mC{Paid job}
        & \mC{Self Employed}\\ 
\midrule
 \multicolumn{7}{c}{\textit{Linear model with optimal bandwidth \hat{h}}} \\
\hline
Treatment & 0.0145 & 0.0324 &-0.0109 & 0.00249 &  0.0119 & -0.0506  & 0.00976 \\
 & (0.0236)  & (0.0264) & (0.0217) & (0.00553) & (0.00997)  &(0.0336)& (0.0253)  \\ 
 Bandwidth & 33 & 31 & 54 & 42 & 30 & 35 & 35\\ 
 Obs & 4,490 & 4,200 & 7,649 & 5,854 & 4,065 & 4,739& 4,739\\
 \addlinespace
 \multicolumn{7}{c}{\textit{Quadratic model with optimal bandwidth \hat{h}}} \\
\hline
Treatment & 0.0149 & 0.0324 & -0.0131& 0.00228 & 0.0127 & -0.0516 & 0.0101\\
 & (0.0235) & (0.0261) & (0.0224) & (0.00554) & (0.00997)  & (0.0323)& (0.0254)  \\ 
 Bandwidth & 33 & 31 & 54 & 42 & 30 & 35 & 35\\ 
 Obs & 4,490 & 4,200 & 7,649 & 5,854 &  4,065& 4,739&4,739 \\
 \addlinespace
 \multicolumn{7}{c}{\textit{Linear model with bandwidth 2\hat{h} }} \\
\hline
Treatment & 0.0205 & 0.0237 & -0.00695& 0.00705  & 0.00767 & -0.0739^{*} &  0.0361\\
 & (0.0269) & (0.0282) & (0.0316) &(0.00735) &(0.00715) & (0.0402) & (0.0303)  \\ 
 Bandwidth & 66 & 62 & 108 & 84 & 60 & 70 & 70\\ 
 Obs & 2,200 & 2,022 & 3,640 & 2,927 &  2,022 & 2,332&2,332 \\
 \addlinespace
 \multicolumn{7}{c}{\textit{Linear model with bandwidth 2\hat{h}/3}} \\
\hline
Treatment & 0.0330 & 0.0313 & -0.0171 & 0.00941 &  0.00853 & -0.0543 & 0.0247 \\
 & (0.0271) & (0.0295) & (0.0288) &(0.00609) & (0.0113)& (0.0374) & (0.0309)  \\ 
 Bandwidth & 22 & 20 & 36 & 28 & 20 & 23 & 23\\ 
 Obs & 3,027 & 2,927 & 4,866 & 3,801 &  2,797& 3,027&3,027 \\
 \addlinespace
 \multicolumn{7}{c}{\textit{Linear model with bandwidth 2\hat{h}}} \\
\hline
Treatment & 0.0192 & 0.0297 & 0.00693 & 0.000796 & 0.00400 & -0.00176 & 0.0134\\
 & (0.0174) & (0.0200) & (0.0150) & (0.00396) & (0.00763) & (0.0219) & (0.0174)  \\ 
 Bandwidth & 16 & 15 & 27 & 21 & 15 & 17 & 17\\ 
 Obs & 9,403 & 8,751 & 15,632 & 12,064 &  8,499 & 9,953 & 9,953\\
 \addlinespace
\bottomrule
\addlinespace
\multicolumn{7}{c}{ $^{***}\ p<0.01$; $^{**}\ p<0.05$; $^{*}\  p<0.1$} \\
\end{tabularx}
\end{table}
\end{document}

这就是我得到的一个例子 在此处输入图片描述

答案1

你实际上不需要对齐所有四行,因此我将整数值行切换为不同的列格式

在此处输入图片描述

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{rotating}
\usepackage{booktabs,tabularx,dcolumn,adjustbox}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\newcolumntype{d}[1]{D..{#1}}
\usepackage[font=small,labelfont=bf,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}}

\begin{document}

\begin{table}[t]
\centering
\caption{Reduced form regressions for labour market outcomes}
\begin{tabular}{@{} l *{7}{d{2.6}} cc @{}} 
\toprule
 & \mc{(1)} & \mc{(2)} & \mc{(3)} & \mc{(4)} & \mc{(5)} & \mc{(6)} & \mc{(7)} \\
\addlinespace
Outcome & \mC{Employed} 
        & \mC{Agricultural\\ Job} 
        & \mC{Non Agric\\. Job}
        & \mC{Service Job}
        & \mC{Occasionally\\ Employed}
        & \mC{Paid job}
        & \mC{Self\\ Employed}\\ 
\midrule
 \multicolumn{7}{c}{\textit{Linear model with optimal bandwidth $\hat{h}$}} \\
\hline
Treatment & 0.0145 & 0.0324 &-0.0109 & 0.00249 &  0.0119 & -0.0506  & 0.00976 \\
 & (0.0236)  & (0.0264) & (0.0217) & (0.00553) & (0.00997)  &(0.0336)& (0.0253)  \\ 
 Bandwidth & \ic{33} & \ic{31} & \ic{54} & \ic{42} & \ic{30} & \ic{35} & \ic{35}\\ 
 Obs & \ic{4,490} & \ic{4,200} & \ic{7,649} & \ic{5,854} & \ic{4,065} & \ic{4,739}& \ic{4,739}\\
 \addlinespace
 \multicolumn{7}{c}{\textit{Quadratic model with optimal bandwidth $\hat{h}$}} \\
\hline
Treatment & 0.0149 & 0.0324 & -0.0131& 0.00228 & 0.0127 & -0.0516 & 0.0101\\
 & (0.0235) & (0.0261) & (0.0224) & (0.00554) & (0.00997)  & (0.0323)& (0.0254)  \\ 
 Bandwidth & \ic{33} & \ic{31} & \ic{54} & \ic{42} & \ic{30} & \ic{35} & \ic{35}\\ 
 Obs & \ic{4,490} & \ic{4,200} & \ic{7,649} & \ic{5,854} &  \ic{4,065}& \ic{4,739}&\ic{4,739} \\
 \addlinespace
 \multicolumn{7}{c}{\textit{Linear model with bandwidth $2\hat{h}$ }} \\
\hline
Treatment & 0.0205 & 0.0237 & -0.00695& 0.00705  & 0.00767 & -0.0739^{*} &  0.0361\\
 & (0.0269) & (0.0282) & (0.0316) &(0.00735) &(0.00715) & (0.0402) & (0.0303)  \\ 
 Bandwidth & \ic{66} & \ic{62} & \ic{108} & \ic{84} & \ic{60} & \ic{70} & \ic{70}\\ 
 Obs & \ic{2,200} & \ic{2,022} & \ic{3,640} & \ic{2,927} &  \ic{2,022} & \ic{2,332}&\ic{2,332} \\
 \addlinespace
 \multicolumn{7}{c}{\textit{Linear model with bandwidth $2\hat{h}/3$}} \\
\hline
Treatment & 0.0330 & 0.0313 & -0.0171 & 0.00941 &  0.00853 & -0.0543 & 0.0247 \\
 & (0.0271) & (0.0295) & (0.0288) &(0.00609) & (0.0113)& (0.0374) & (0.0309)  \\ 
 Bandwidth & \ic{22} & \ic{20} & \ic{36} & \ic{28} & \ic{20} & \ic{23} & \ic{23}\\ 
 Obs & \ic{3,027} & \ic{2,927} & \ic{4,866} & \ic{3,801} &  \ic{2,797}& \ic{3,027}&\ic{3,027} \\
 \addlinespace
 \multicolumn{7}{c}{\textit{Linear model with bandwidth $2\hat{h}$}} \\
\hline
Treatment & 0.0192 & 0.0297 & 0.00693 & 0.000796 & 0.00400 & -0.00176 & 0.0134\\
 & (0.0174) & (0.0200) & (0.0150) & (0.00396) & (0.00763) & (0.0219) & (0.0174)  \\ 
 Bandwidth & \ic{16} & \ic{15} & \ic{27} & \ic{21} & \ic{15} & \ic{17} & \ic{17}\\ 
 Obs & \ic{9,403} & \ic{8,751} & \ic{15,632} & \ic{12,064} &  \ic{8,499} & \ic{9,953} & \ic{9,953}\\
 \addlinespace
\bottomrule
\addlinespace
\multicolumn{7}{c}{ $^{***}\ p<0.01$; $^{**}\ p<0.05$; $^{*}\  p<0.1$} \\
\end{tabular}
\end{table}
\end{document}

相关内容