我看到了很多针对这个特定问题的答案。但是,是否可以将一列文本拆分成单独的行,例如在环境中tabularx
添加换行符mulitcolumn
tabular
到目前为止我的表格是这样的:
\begin{table}[!htbp] \centering
\caption{Means of the key variable}
\label{}
\small
\begin{tabular}{@{\extracolsep{1pt}} D{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} }
\\[-1.8ex]\hline \\[-1.8ex]
\multicolumn{1}{c}{country} & \multicolumn{1}{c}{log\_w} & \multicolumn{1}{c}{s} & \multicolumn{1}{c}{ycomp} & \multicolumn{1}{c}{Change in yrs. of comp. school} & \multicolumn{1}{c}{Age} & \multicolumn{1}{c}{\% Males} & \multicolumn{1}{c}{Nobs} & \multicolumn{1}{c}{\% Complier} \\
\hline \\[-1.8ex]
\multicolumn{1}{c}{Austria} & \multicolumn{1}{c}{2.022} & \multicolumn{1}{c}{12.632} & \multicolumn{1}{c}{8.679} & \multicolumn{1}{c}{8 to 9} & \multicolumn{1}{c}{55.368} & \multicolumn{1}{c}{0.526} & \multicolumn{1}{c}{209} & \multicolumn{1}{c}{0.679} \\
\multicolumn{1}{c}{Belgium} & \multicolumn{1}{c}{2.288} & \multicolumn{1}{c}{12.162} & \multicolumn{1}{c}{8.005} & \multicolumn{1}{c}{8 to 12} & \multicolumn{1}{c}{53.234} & \multicolumn{1}{c}{0.543} & \multicolumn{1}{c}{877} & \multicolumn{1}{c}{0.001} \\
\multicolumn{1}{c}{Denmark} & \multicolumn{1}{c}{2.973} & \multicolumn{1}{c}{13.523} & \multicolumn{1}{c}{7.115} & \multicolumn{1}{c}{7 to 9} & \multicolumn{1}{c}{54.592} & \multicolumn{1}{c}{0.489} & \multicolumn{1}{c}{681} & \multicolumn{1}{c}{0.057} \\
\multicolumn{1}{c}{France} & \multicolumn{1}{c}{2.401} & \multicolumn{1}{c}{11.303} & \multicolumn{1}{c}{8.64} & \multicolumn{1}{c}{8 to 10} & \multicolumn{1}{c}{53.328} & \multicolumn{1}{c}{0.474} & \multicolumn{1}{c}{878} & \multicolumn{1}{c}{0.32} \\
\multicolumn{1}{c}{Germany} & \multicolumn{1}{c}{2.58} & \multicolumn{1}{c}{14.705} & \multicolumn{1}{c}{8.645} & \multicolumn{1}{c}{8 to 9} & \multicolumn{1}{c}{55.309} & \multicolumn{1}{c}{0.51} & \multicolumn{1}{c}{857} & \multicolumn{1}{c}{0.645} \\
\multicolumn{1}{c}{Greece} & \multicolumn{1}{c}{2.038} & \multicolumn{1}{c}{12.22} & \multicolumn{1}{c}{6.148} & \multicolumn{1}{c}{6 to 9} & \multicolumn{1}{c}{54.182} & \multicolumn{1}{c}{0.617} & \multicolumn{1}{c}{708} & \multicolumn{1}{c}{0.049} \\
\multicolumn{1}{c}{Italy} & \multicolumn{1}{c}{2.196} & \multicolumn{1}{c}{10.066} & \multicolumn{1}{c}{7.112} & \multicolumn{1}{c}{5 to 9} & \multicolumn{1}{c}{55.606} & \multicolumn{1}{c}{0.601} & \multicolumn{1}{c}{411} & \multicolumn{1}{c}{0.528} \\
\multicolumn{1}{c}{Netherlands} & \multicolumn{1}{c}{2.748} & \multicolumn{1}{c}{13.289} & \multicolumn{1}{c}{9.02} & \multicolumn{1}{c}{9 to 10} & \multicolumn{1}{c}{54.69} & \multicolumn{1}{c}{0.535} & \multicolumn{1}{c}{910} & \multicolumn{1}{c}{0.02} \\
\multicolumn{1}{c}{Spain} & \multicolumn{1}{c}{2.039} & \multicolumn{1}{c}{9.487} & \multicolumn{1}{c}{8.671} & \multicolumn{1}{c}{6 to 8} & \multicolumn{1}{c}{55.355} & \multicolumn{1}{c}{0.567} & \multicolumn{1}{c}{383} & \multicolumn{1}{c}{0.671} \\
\multicolumn{1}{c}{Sweden} & \multicolumn{1}{c}{2.597} & \multicolumn{1}{c}{12.766} & \multicolumn{1}{c}{7.154} & \multicolumn{1}{c}{8 to 9} & \multicolumn{1}{c}{56.396} & \multicolumn{1}{c}{0.46} & \multicolumn{1}{c}{1251} & \multicolumn{1}{c}{0.577} \\
\hline \\[-1.8ex]
\end{tabular}
\end{table}
当然我会接受解决方案,tabularx
但由于我从未使用过它,因此如果可能的话我建议留在该tabular
环境中。
答案1
我建议使用 、 和 来提出这种变siunitx
体eqparbox
解决makecell
方案collcell
:
\documentclass{article}
\usepackage{booktabs, ragged2e, eqparbox}
\usepackage{siunitx, collcell, makecell}
\newcommand{\range}[1]{\eqparbox{ra}{#1}}
\newcolumntype{R}{>{\collectcell\range}c<{\endcollectcell}}
\begin{document}
\begin{table}[!htbp]
\setlength\tabcolsep{3pt}
\sisetup{table-format=1.3, table-number-alignment=center}
\centering
\caption{Means of the key variable\strut} \label{}
\small
\begin{tabular}{@{} l SS[table-format=2.3]SRS[table-format=2.3]SS[table-format=4]S @{}}
\toprule
Country & {log w} & {s} & {ycomp} & \multicolumn{1}{c}{\makecell{Change in yrs.\\ of comp. school}}
& {Age} & {\makecell{\%\\ Males}} & {Nobs} & {\makecell{\%\\ Complier}} \\
\midrule
Austria & 2.022 & 12.632 & 8.679 & 8 to 9 & 55.368 & 0.526 & 209 & 0.679 \\
Belgium & 2.288 & 12.162 & 8.005 & 8 to 12 & 53.234 & 0.543 & 877 & 0.001 \\
Denmark & 2.973 & 13.523 & 7.115 & 7 to 9 & 54.592 & 0.489 & 681 & 0.057 \\
France & 2.401 & 11.303 & 8.64 & 8 to 10 & 53.328 & 0.474 & 878 & 0.32 \\
Germany & 2.58 & 14.705 & 8.645 & 8 to 9 & 55.309 & 0.51 & 857 & 0.645 \\
Greece & 2.038 & 12.22 & 6.148 & 6 to 9 & 54.182 & 0.617 & 708 & 0.049 \\
Italy & 2.196 & 10.066 & 7.112 & 5 to 9 & 55.606 & 0.601 & 411 & 0.528 \\
Netherlands & 2.748 & 13.289 & 9.02 & 9 to 10 & 54.69 & 0.535 & 910 & 0.02 \\
Spain & 2.039 & 9.487 & 8.671 & 6 to 8 & 55.355 & 0.567 & 383 & 0.671 \\
Sweden & 2.597 & 12.766 & 7.154 & 8 to 9 & 56.396 & 0.46 & 1251 & 0.577 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案2
我不明白为什么每个表格单元格都被包裹在\multicolumn{1}{c}{...}
包装器中。
D
我会 (a)根据每列数字的特征定制列类型的参数,以及 (b) 使用tabularx
环境允许在表格的标题单元格中换行。
您可能想要考虑一个比“学校年限变化”更短的标题。
\documentclass{article}
\usepackage{booktabs,dcolumn,tabularx,ragged2e}
\newcolumntype{d}[1]{D..{#1}}
\newcolumntype{C}{>{\Centering\hspace{0pt}}X}
\newcommand\mC[1]{\multicolumn{1}{C}{#1}}
\begin{document}
\begin{table}[!htbp]
\setlength\tabcolsep{2pt}
\caption{Means of the key variable\strut} \label{}
\small
\begin{tabularx}{\textwidth}{@{} l d{1.3} d{2.3} d{1.3} c
d{2.3} d{1.3} d{4.0} d{1.3} @{}}
\toprule
Country & \mC{log w} & \mC{s} & \mC{ycomp} & \mC{Change in yrs.\ of comp.\ school}
& \mC{Age} & \mC{\% Males} & \mC{Nobs} & \mC{\% Complier} \\
\midrule
Austria & 2.022 & 12.632 & 8.679 & 8 to 9 & 55.368 & 0.526 & 209 & 0.679 \\
Belgium & 2.288 & 12.162 & 8.005 & 8 to 12 & 53.234 & 0.543 & 877 & 0.001 \\
Denmark & 2.973 & 13.523 & 7.115 & 7 to 9 & 54.592 & 0.489 & 681 & 0.057 \\
France & 2.401 & 11.303 & 8.64 & 8 to 10 & 53.328 & 0.474 & 878 & 0.32 \\
Germany & 2.58 & 14.705 & 8.645 & 8 to 9 & 55.309 & 0.51 & 857 & 0.645 \\
Greece & 2.038 & 12.22 & 6.148 & 6 to 9 & 54.182 & 0.617 & 708 & 0.049 \\
Italy & 2.196 & 10.066 & 7.112 & 5 to 9 & 55.606 & 0.601 & 411 & 0.528 \\
Netherlands & 2.748 & 13.289 & 9.02 & 9 to 10 & 54.69 & 0.535 & 910 & 0.02 \\
Spain & 2.039 & 9.487 & 8.671 & 6 to 8 & 55.355 & 0.567 & 383 & 0.671 \\
Sweden & 2.597 & 12.766 & 7.154 & 8 to 9 & 56.396 & 0.46 & 1251 & 0.577 \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}