所以我的问题是:我的表中的一些变量有多个类别,而其他变量没有。但是,我希望在单独的变量之间留出更多空间,但是不是具有变量不同类别的行之间的差距。例如,我希望“注册学生”和“性别(%)”之间的差距更大,而“男性和女性”之间的差距较小。同样,我希望“女性”和“种族(%)”之间的差距(与“注册学生和性别”之间的差距相同),而白人/黑人/有色人种/印度人/亚洲人之间的差距较小(与男性和女性之间的差距相同)。然后,印度人/亚洲人在获得经济援助的情况下的差距更大(与注册学生/性别和性别/种族之间的差距相同)。
我的 MWE(不要担心列宽看起来很奇怪,我可以自己改变它们!)
\documentclass{article}
\usepackage{booktabs}
\usepackage[flushleft]{threeparttable}
\usepackage{verbatim} % Needed for the "comment" environment to make LaTeX comments
\renewcommand\arraystretch{1.4}
\begin{document}
\begin{table}[H]
\renewcommand\arraystretch{1.4}
\begin{threeparttable}
\caption{Summary Statistics}
\label{table:ssna}
\begin{tabular}{p{0.30\textwidth} p{0.15\textwidth} p{0.15\textwidth} p{0.15\textwidth} p{0.15\textwidth} p{0.15\textwidth}}
\toprule
& \multicolumn{5}{c}{\bfseries Cohort} \\
\cmidrule(l){2-6}
& 2006 & 2007 & 2008 & 2009 & 2010 \\
\midrule
{\bfseries Students registered} & 1535 & 1584 & 1767 & 2037 & 1518 \\
{\bfseries Gender (\%)} & & & & & \\
Male & 61.1 & 64.5 & 57.7 & 55.5 & 55.3 \\
Female & 38.9 & 35.5 & 42.3 & 44.5 & 44.7 \\
{\bfseries Race (\%)} & & & & & \\
White & 43.3 & 43.4 & 40.6 & 36 & 39.8 \\
Black & 29.8 & 33.4 & 34.8 & 38 & 35.4 \\
Coloured & 16 & 13 & 13.8 & 12.9 & 11.5 \\
Indian/Asian & 10.8 & 10.1 & 10.8 & 13.1 & 13.4 \\
{\bfseries Financial Aid (\%)} & 19.5 & 22.3 & 25.2 & 29.9 & 24.5 \\
{\bfseries AD Programme (\%)} & 24 & 20.3 & 18.6 & 20.6 & 21.9 \\
\bottomrule
\end{tabular}
\begin{tablenotes}
\small
\item Source: UCT Institutional Planning Department
\end{tablenotes}
\end{threeparttable}
\end{table}
\end{document}
答案1
我认为一开始就设置为 1.4 是错误的\arraystretch
。表格太分散,在不同的组之间添加垂直空间也无济于事。此外,列的宽度应该尽可能宽,而不是更宽。
无需设置,\arraystretch
您可以使用\addlinespace
或添加\midrule
:
\documentclass{article}
\usepackage{booktabs,siunitx}
\usepackage[flushleft]{threeparttable}
\begin{document}
\begin{table}
\begin{threeparttable}
\caption{Summary Statistics}
\label{table:ssna}
\begin{tabular}{
l
*{5}{S[table-format=2.1]}
}
\toprule
& \multicolumn{5}{c}{\bfseries Cohort} \\
\cmidrule(l){2-6}
& {2006} & {2007} & {2008} & {2009} & {2010} \\
\midrule
\bfseries Students registered & {1535} & {1584} & {1767} & {2037} & {1518} \\
\addlinespace
\bfseries Gender (\%) \\
Male & 61.1 & 64.5 & 57.7 & 55.5 & 55.3 \\
Female & 38.9 & 35.5 & 42.3 & 44.5 & 44.7 \\
\addlinespace
\bfseries Race (\%) \\
White & 43.3 & 43.4 & 40.6 & 36 & 39.8 \\
Black & 29.8 & 33.4 & 34.8 & 38 & 35.4 \\
Coloured & 16 & 13 & 13.8 & 12.9 & 11.5 \\
Indian/Asian & 10.8 & 10.1 & 10.8 & 13.1 & 13.4 \\
\addlinespace
\bfseries Financial Aid (\%) & 19.5 & 22.3 & 25.2 & 29.9 & 24.5 \\
\addlinespace
\bfseries AD Programme (\%) & 24 & 20.3 & 18.6 & 20.6 & 21.9 \\
\bottomrule
\end{tabular}
\begin{tablenotes}
\small
\item Source: UCT Institutional Planning Department
\end{tablenotes}
\end{threeparttable}
\end{table}
\end{document}
\midrule
使用 替换可以得到以下结果\addlinespace
:
如果希望表格的宽度与文本宽度一样宽,可以使用tabular*
:
\documentclass{article}
\usepackage{booktabs,siunitx,array}
\usepackage[flushleft]{threeparttable}
\usepackage{lipsum} % just for the example
\begin{document}
\lipsum[2]
\begin{table}[htp]
\begin{threeparttable}
\caption{Summary Statistics}
\label{table:ssna}
\begin{tabular*}{\textwidth}{
!{\extracolsep{\fill}}
l
*{5}{S[table-format=2.1]}
}
\toprule
& \multicolumn{5}{c}{\bfseries Cohort} \\
\cmidrule(l){2-6}
& {2006} & {2007} & {2008} & {2009} & {2010} \\
\midrule
\bfseries Students registered & {1535} & {1584} & {1767} & {2037} & {1518} \\
\midrule
\bfseries Gender (\%) \\
Male & 61.1 & 64.5 & 57.7 & 55.5 & 55.3 \\
Female & 38.9 & 35.5 & 42.3 & 44.5 & 44.7 \\
\midrule
\bfseries Race (\%) \\
White & 43.3 & 43.4 & 40.6 & 36 & 39.8 \\
Black & 29.8 & 33.4 & 34.8 & 38 & 35.4 \\
Coloured & 16 & 13 & 13.8 & 12.9 & 11.5 \\
Indian/Asian & 10.8 & 10.1 & 10.8 & 13.1 & 13.4 \\
\midrule
\bfseries Financial Aid (\%) & 19.5 & 22.3 & 25.2 & 29.9 & 24.5 \\
\midrule
\bfseries AD Programme (\%) & 24 & 20.3 & 18.6 & 20.6 & 21.9 \\
\bottomrule
\end{tabular*}
\begin{tablenotes}
\small
\item Source: UCT Institutional Planning Department
\end{tablenotes}
\end{threeparttable}
\end{table}
\end{document}
请注意,这\lipsum
仅用于提供一些背景信息。我确信这比表格的“自然”宽度更糟糕。
答案2
您可以使用makecell
(numprint
并将列对齐到小数点上):
\documentclass{article}
\usepackage{booktabs}
\usepackage[flushleft]{threeparttable}
\usepackage{verbatim} % Needed for the "comment" environment to make LaTeX comments
\renewcommand\arraystretch{1.4}
\usepackage{makecell}
\renewcommand\theadfont{\bfseries}
\renewcommand\theadalign{lc}
\renewcommand\theadgape{\Gape[10pt][0pt]}
\usepackage[autolanguage]{numprint}
\begin{document}
\begin{table}[H]
\renewcommand\arraystretch{1.4}
\renewcommand{\tabcolsep}{12pt}
\begin{threeparttable}
\caption{Summary Statistics}
\label{table:ssna}
\begin{tabular}{@{}p{0.30\textwidth}*{5}{n{2}{1}}@{}}
\toprule
& \multicolumn{5}{c}{\bfseries Cohort} \\
\cmidrule(l){2-6}
& {2006} & {2007} & {2008} &{ 2009}& {2010} \\
\midrule
\thead{Students registered} & {1535} & {1584} & {1767} & {2037} & {1518} \\
\thead{Gender (\%)} & & & & & \\
Male & 61.1 & 64.5 & 57.7 & 55.5 & 55.3 \\
Female & 38.9 & 35.5 & 42.3 & 44.5 & 44.7 \\
\thead{Race (\%)} & & & & & \\
White & 43.3 & 43.4 & 40.6 & 36 & 39.8 \\
Black & 29.8 & 33.4 & 34.8 & 38 & 35.4 \\
Coloured & 16& 13 & 13.8 & 12.9 & 11.5 \\
Indian/Asian & 10.8 & 10.1 & 10.8 & 13.1 & 13.4 \\
\thead{Financial Aid (\%)} & 19.5 & 22.3 & 25.2 & 29.9 & 24.5 \\
\thead{AD Programme (\%)} & 24. & 20.3 & 18.6 & 20.6 & 21.9 \\
\bottomrule
\end{tabular}
\begin{tablenotes}
\small
\item Source: UCT Institutional Planning Department
\end{tablenotes}
\end{threeparttable}
\end{table}
\end{document}