第二种选择

第二种选择

我的主管要求我将三个垂直表格合并为一个水平/横向表格。我的表格代码(至少是格式部分)相当复杂,这是我第一次尝试制作横向表格。不幸的是,我有点卡住了,我想我知道我哪里出错了(列宽等),但我不确定如何修复它。我在下面给出了我的表格的模型,以了解我想要得到什么:

在此处输入图片描述

这是我的 MWE

\documentclass{article}
\usepackage{pdflscape}
\usepackage{afterpage}
\usepackage{booktabs}
\usepackage{siuntix}
\usepackage{array}
\usepackage{ragged2e}
\usepackage{capt-of}% or use the larger `caption` package
\begin{document}
\afterpage{
\clearpage
\thispagestyle{empty}
\begin{landscape}
\begin{table}
\centering
\begin{tabular*}
\small
{ 
 >{\RaggedRight\arraybackslash}p{.17\textwidth} 
 S *{3}{S[table-format=2.1] >{\footnotesize}S[table-format=3.2,input-symbols=()]} }
  \caption {Descriptive Statistics (\%): Commerce, EBE and Science faculties}      
\label{table:DSCF} \\
\toprule
{\bfseries Variable} & 
 \multicolumn{3}{c}{\bfseries Commerce}\\
 \multicolumn{3}{c}{\bfseries EBE} \\
 \multicolumn{3}{c}{\bfseries Science} \\
 \multicolumn{3}{c}{\bfseries Total} \\
\cmidrule{2-13}
&&
\multicolumn{1}{C{.19\textwidth}}{\bfseries Graduated} & \multicolumn{1}{C{.19\textwidth}}{\bfseries Academically Excluded} & 
\multicolumn{1}{C{.19\textwidth}}{\bfseries Censored}
\multicolumn{1}{C{.19\textwidth}}{\bfseries Graduated} & \multicolumn{1}{C{.19\textwidth}}{\bfseries Academically Excluded} & 
\multicolumn{1}{C{.19\textwidth}}{\bfseries Censored}
\multicolumn{1}{C{.19\textwidth}}{\bfseries Graduated} & \multicolumn{1}{C{.19\textwidth}}{\bfseries Academically Excluded} & 
\multicolumn{1}{C{.19\textwidth}}{\bfseries Censored}
\multicolumn{1}{C{.19\textwidth}}{\bfseries Graduated} & \multicolumn{1}{C{.19\textwidth}}{\bfseries Academically Excluded} & 
 \multicolumn{1}{C{.19\textwidth}}{\bfseries Censored}\\
\midrule
\bfseries Total & 50.1 & 7.5 & 42.4 & 35.8 & 21.6 & 42.7 & 46.4 & 26.1 & 27.5 & & 45.8 & 14.9 & 39.3    \\
\addlinespace
\bfseries Gender\\
Male                 & 49.6 & 8.7  & 41.7 & 36.4 & 21.9 & 41.7 & 44.0 & 31.2 & 24.9 & 44.3 & 17.3 & 38.5 \\
Female               & 50.7 & 6.2  & 43.1 & 33.8 & 20.6 & 45.7 & 49.3 & 20.2 & 30.5 & 48.0 & 11.5 & 40.5 \\
\addlinespace
\bfseries Race\\
White & 59.8 & 3.0 & 37.2 & 50.8 & 7.8 & 41.3 & 64.5 & 5.1 & 30.4 & & 58.7 & 4.6 & 36.7  \\
Black & 38.7 & 13.1 & 48.2 & 22.2 &34.9& 43.0 & 31.0 & 44.5 & 24.5 & 32.5 & 26.3 &41.2(\\
Coloured & 49.8 & 7.4 & 42.8 & 36.4 & 21.9 & 41.6 & 40.2 & 30.6 & 29.2 & 44.5 & 16.1 & 39.5   \\
Indian/Asian & 48.9  & 7.9 & 43.3 & 32.7 & 20.5 & 46.9 & 32.7 & 20.5 & 46.9 & 44.6 & 13.3 & 42.1\\
\addlinespace
\bfseries Financial Aid\\
Ineligible for Financial Aid & 52.1  & 5.5  & 42.4 & 38.0 & 17.7 & 44.3 & 38.0 & 17.7 & 44.3 & 48.7 & 10.6 & 40.7  \\
Eligible for Financial Aid  & 40.7 & 17.2 & 42.1 & 26.5 & 37.5 & 36.1 & 33.8 & 42.9 & 23.3 & 35.2 & 30.3 & 34.5 \\
\addlinespace
\bfseries Programme\\
Mainstream  & 55.4  & 5.7 & 38.9 & 40.5 & 17.3 & 42.3 & 54.3 & 16.4 & 29.3 & 51.3 & 10.8 & 37.9  \\
Academic Development & 32.5 & 13.7 & 53.8 & 14.1 & 41.4 & 44.5 & 25.3 & 51.8 & 22.8 & 27.1 & 28.7 & 44.2 \\
\addlinespace
\bfseries English Home Language\\
Yes  & 55.1 & 4.9 & 39.9 & 44.1 & 13.3 & 42.6 & 56.3 & 14.1 & 29.6 & 52.8 & 8.6 & 38.6 \\
No & 38.8 & 13.4  & 47.8 & 22.3 &  35.0 & 42.7 & 32.7 & 42.7 & 24.6 & 32.8 & 26.6 & 40.6 \\
\addlinespace
\bfseries School Quintile\\
1  & 34.6 & 30.8 & 34.6 & 14.1 & 49.3 & 36.6 & 34.0 & 45.3 & 20.8 & 26.1 & 42.6 & 31.3  \\
2  & 30.2 & 16.0 & 53.8 & 25.6 & 36.4 & 38.0 & 28.8 & 50.9 & 20.3 & 28.1 & 35.1 & 36.8 \\
3  & 32.0 & 17.5 & 50.5 & 21.7 & 41.9 & 36.5 & 30.0 & 45.8 & 24.2 & 27.7 & 35.3 & 37.0 \\
4  & 37.7 & 17.7 & 44.5 & 17.7 & 38.0 & 44.3 & 30.0 & 46.7 & 23.3 & 29.5 & 32.0 & 38.5 \\
5  & 52.0 & 6.9 & (41.1 & 41.0 & 16.2 & 42.9 & 54.3 & 14.8 & 31.0 & 49.2 & 12.0 & 38.9  \\
Independent  & 52.5 & 5.3 & 42.2 & 40.7 & 13.9 & 45.5 & 54.3 &14.8 & 31.0  50.4 & 8.6 & 41.0 \\
\addlinespace
{\bfseries Province}\\
Western Cape & 55.1 & 5.9 &39.0 & 42.1 &16.2 &41.7 & 52.0 &20.0 & 28.0 & 51.3 & 11.6 &37.0 \\
Non-Western Cape &46.8 & 8.6 & 44.6 & 31.6 & 25.1 & 43.3 & 41.5 & 31.5 & 27.1 & 41.9 & 17.2 &41.0\\
\addlinespace
{\bfseries Year of First Registration} \\
{2006}  87.8 & 11.3 & 0.9 & 70.3 & 29.0 & 0.7 & 69.5 & 28.2 & 2.3 & 79.9 & 18.9 &1.2  \\
{2007} 88.2 & 10.1 &  1.7 & 68.7 & 30.0 & 1.4 & 68.5 & 30.8 & 0.7 & 79.4 &19.2 &1.4\\
{2008} 87.1 & 10.3 &  2.6 & 63.6 & 30.6 & 5.8 & 66.2 & 32.3 & 1.6 & 76.7 & 20.3 & 3.0 \\
{2009} 80.9 & 9.7 & 9.4 & 51.2   & 32.3 &16.5 & 51.9 & 43.9 & 4.2 & 64.9 & 24.9 & 10.2 \\
{2010} 62.6 & 6.4 & 31.1 & 36.8 & 19.0 & 44.2 & 69.8 & 21.0 & 9.3 & 57.5 & 12.7 & 29.8 \\
{2011} 15.8 & 7.2 & 77.0 & 0.0 & 18.2  & 81.8 & 37.3 & 23.4 & 39.8 & 15.3 & 12.8 & 71.9 \\
{2012} 0.0 & 5.4 & 94.6 &  0.0 & 7.5 & 92.5 & 0.0 & 13.4 & 86.6 & 0.0 & 7.5 & 92.5 \\
{2013} 0.0 & 1.7 & 98.3 & 0.0 & 4.9  & 95.1 & 0.0 & 5.1  & 94.9 & 0.0 & 3.0 & 97.0 \\
\end{tabular*}
\end{table}
\end{landscape}
\clearpage
 }
\end{document}

答案1

我建议将较长的列标题(毕业、学术开除、审查)替换为缩写(G、AE、C),并在标题中描述关键内容。然后,您可以轻松地将所有列放在横向页面中。

这里和那里还有很多其他的小变化。我不确定我是否记得全部,但是:

  • 新的列规范。一p列后面跟着 12S列。
  • 从几个数字中删除了一些括号。
  • 删除了一些多余的&,也添加了一些需要的。
  • longtable被使用。我认为表格太长,无法放在一页中。
  • 每个最顶部的列标题(Commerce、EBE 等)后面都有换行符,这些应该是&
  • 四个单独的cmidrules,经过一些修剪,而不是一个长的 s。

\documentclass{article}
\usepackage{pdflscape,ragged2e,array,siunitx,longtable,booktabs}
\usepackage{afterpage}
\usepackage{capt-of}% or use the larger `caption` package
\begin{document}
\begin{landscape}
\centering
\small
\begin{longtable}{
 >{\RaggedRight\arraybackslash}p{.35\textwidth} 
 *{12}{S[table-format=2.1]}}
  \caption{Descriptive Statistics (\%): Commerce, EBE and Science faculties. Key: \textbf{G}: Graduate, \textbf{AE}: Academically Excluded, \textbf{C}: Censored}      
\label{table:DSCF} \\
\toprule
{\bfseries Variable} & 
 \multicolumn{3}{c}{\bfseries Commerce} &
 \multicolumn{3}{c}{\bfseries EBE} &
 \multicolumn{3}{c}{\bfseries Science} &
 \multicolumn{3}{c}{\bfseries Total} \\
\cmidrule(rl){2-4}
\cmidrule(rl){5-7}
\cmidrule(rl){8-10}
\cmidrule(rl){11-13}
&
{\bfseries G} & {\bfseries AE} & 
{\bfseries C} &
{\bfseries G} & {\bfseries AE} & 
{\bfseries C} &
{\bfseries G} & {\bfseries AE} & 
{\bfseries C} &
{\bfseries G} & {\bfseries AE} & 
 {\bfseries C}\\
\midrule
\bfseries Total & 50.1 & 7.5 & 42.4 & 35.8 & 21.6 & 42.7 & 46.4 & 26.1 & 27.5 & 45.8 & 14.9 & 39.3    \\
\addlinespace
\bfseries Gender\\
Male                 & 49.6 & 8.7  & 41.7 & 36.4 & 21.9 & 41.7 & 44.0 & 31.2 & 24.9 & 44.3 & 17.3 & 38.5 \\
Female               & 50.7 & 6.2  & 43.1 & 33.8 & 20.6 & 45.7 & 49.3 & 20.2 & 30.5 & 48.0 & 11.5 & 40.5 \\
\addlinespace
\bfseries Race\\
White & 59.8 & 3.0 & 37.2 & 50.8 & 7.8 & 41.3 & 64.5 & 5.1 & 30.4 &  58.7 & 4.6 & 36.7  \\
Black & 38.7 & 13.1 & 48.2 & 22.2 &34.9& 43.0 & 31.0 & 44.5 & 24.5 & 32.5 & 26.3 &41.2\\
Coloured & 49.8 & 7.4 & 42.8 & 36.4 & 21.9 & 41.6 & 40.2 & 30.6 & 29.2 & 44.5 & 16.1 & 39.5   \\
Indian/Asian & 48.9  & 7.9 & 43.3 & 32.7 & 20.5 & 46.9 & 32.7 & 20.5 & 46.9 & 44.6 & 13.3 & 42.1\\
\addlinespace
\bfseries Financial Aid\\
Ineligible for Financial Aid & 52.1  & 5.5  & 42.4 & 38.0 & 17.7 & 44.3 & 38.0 & 17.7 & 44.3 & 48.7 & 10.6 & 40.7  \\
Eligible for Financial Aid  & 40.7 & 17.2 & 42.1 & 26.5 & 37.5 & 36.1 & 33.8 & 42.9 & 23.3 & 35.2 & 30.3 & 34.5 \\
\addlinespace
\bfseries Programme\\
Mainstream  & 55.4  & 5.7 & 38.9 & 40.5 & 17.3 & 42.3 & 54.3 & 16.4 & 29.3 & 51.3 & 10.8 & 37.9  \\
Academic Development & 32.5 & 13.7 & 53.8 & 14.1 & 41.4 & 44.5 & 25.3 & 51.8 & 22.8 & 27.1 & 28.7 & 44.2 \\
\addlinespace
\bfseries English Home Language\\
Yes  & 55.1 & 4.9 & 39.9 & 44.1 & 13.3 & 42.6 & 56.3 & 14.1 & 29.6 & 52.8 & 8.6 & 38.6 \\
No & 38.8 & 13.4  & 47.8 & 22.3 &  35.0 & 42.7 & 32.7 & 42.7 & 24.6 & 32.8 & 26.6 & 40.6 \\
\addlinespace
\bfseries School Quintile\\
1  & 34.6 & 30.8 & 34.6 & 14.1 & 49.3 & 36.6 & 34.0 & 45.3 & 20.8 & 26.1 & 42.6 & 31.3  \\
2  & 30.2 & 16.0 & 53.8 & 25.6 & 36.4 & 38.0 & 28.8 & 50.9 & 20.3 & 28.1 & 35.1 & 36.8 \\
3  & 32.0 & 17.5 & 50.5 & 21.7 & 41.9 & 36.5 & 30.0 & 45.8 & 24.2 & 27.7 & 35.3 & 37.0 \\
4  & 37.7 & 17.7 & 44.5 & 17.7 & 38.0 & 44.3 & 30.0 & 46.7 & 23.3 & 29.5 & 32.0 & 38.5 \\
5  & 52.0 & 6.9 & 41.1 & 41.0 & 16.2 & 42.9 & 54.3 & 14.8 & 31.0 & 49.2 & 12.0 & 38.9  \\
Independent  & 52.5 & 5.3 & 42.2 & 40.7 & 13.9 & 45.5 & 54.3 &14.8 & 31.0 & 50.4 & 8.6 & 41.0 \\
\addlinespace
{\bfseries Province}\\
Western Cape & 55.1 & 5.9 &39.0 & 42.1 &16.2 &41.7 & 52.0 &20.0 & 28.0 & 51.3 & 11.6 &37.0 \\
Non-Western Cape &46.8 & 8.6 & 44.6 & 31.6 & 25.1 & 43.3 & 41.5 & 31.5 & 27.1 & 41.9 & 17.2 &41.0\\
\addlinespace
{\bfseries Year of First Registration} \\
{2006} &  87.8 & 11.3 & 0.9 & 70.3 & 29.0 & 0.7 & 69.5 & 28.2 & 2.3 & 79.9 & 18.9 &1.2  \\
{2007} & 88.2 & 10.1 &  1.7 & 68.7 & 30.0 & 1.4 & 68.5 & 30.8 & 0.7 & 79.4 &19.2 &1.4\\
{2008} & 87.1 & 10.3 &  2.6 & 63.6 & 30.6 & 5.8 & 66.2 & 32.3 & 1.6 & 76.7 & 20.3 & 3.0 \\
{2009} & 80.9 & 9.7 & 9.4 & 51.2   & 32.3 &16.5 & 51.9 & 43.9 & 4.2 & 64.9 & 24.9 & 10.2 \\
{2010} & 62.6 & 6.4 & 31.1 & 36.8 & 19.0 & 44.2 & 69.8 & 21.0 & 9.3 & 57.5 & 12.7 & 29.8 \\
{2011} & 15.8 & 7.2 & 77.0 & 0.0 & 18.2  & 81.8 & 37.3 & 23.4 & 39.8 & 15.3 & 12.8 & 71.9 \\
{2012} & 0.0 & 5.4 & 94.6 &  0.0 & 7.5 & 92.5 & 0.0 & 13.4 & 86.6 & 0.0 & 7.5 & 92.5 \\
{2013} & 0.0 & 1.7 & 98.3 & 0.0 & 4.9  & 95.1 & 0.0 & 5.1  & 94.9 & 0.0 & 3.0 & 97.0 \\
\end{longtable}
\end{landscape}
\end{document}

在此处输入图片描述

第二种选择

通过重写/缩短第一列中的条目并减少,\tabcolsep您实际上可以将整个内容压缩到纵向模式下的一页中。如果实际文档中的文本块比默认的文本块更宽,article您将有更多的操作空间,因此您可以将内容做得比下面的代码更宽。(屏幕截图中的框架来自加载包showframe,它只是为了证明表格实际上在文本块的宽度范围内。)

在此处输入图片描述

\documentclass{article}
\usepackage{ragged2e,array,siunitx,longtable,booktabs}
\begin{document}
\begin{table}
\centering
\small
\setlength{\tabcolsep}{3.7pt}
 \caption{Descriptive Statistics (\%): Commerce, EBE and Science faculties. Key: \textbf{G}: Graduate, \textbf{AE}: Academically Excluded, \textbf{C}: Censored}      
\label{table:DSCF}
\begin{tabular}{
 >{\RaggedRight\arraybackslash}p{.15\textwidth} 
 *{12}{S[table-format=2.1]}}
\toprule
{\bfseries Variable} & 
 \multicolumn{3}{c}{\bfseries Commerce} &
 \multicolumn{3}{c}{\bfseries EBE} &
 \multicolumn{3}{c}{\bfseries Science} &
 \multicolumn{3}{c}{\bfseries Total} \\
\cmidrule(rl){2-4}
\cmidrule(rl){5-7}
\cmidrule(rl){8-10}
\cmidrule(rl){11-13}
&
{\bfseries G} & {\bfseries AE} & 
{\bfseries C} &
{\bfseries G} & {\bfseries AE} & 
{\bfseries C} &
{\bfseries G} & {\bfseries AE} & 
{\bfseries C} &
{\bfseries G} & {\bfseries AE} & 
 {\bfseries C}\\
\midrule
\bfseries Total & 50.1 & 7.5 & 42.4 & 35.8 & 21.6 & 42.7 & 46.4 & 26.1 & 27.5 & 45.8 & 14.9 & 39.3    \\
\addlinespace
\bfseries Gender\\
Male                 & 49.6 & 8.7  & 41.7 & 36.4 & 21.9 & 41.7 & 44.0 & 31.2 & 24.9 & 44.3 & 17.3 & 38.5 \\
Female               & 50.7 & 6.2  & 43.1 & 33.8 & 20.6 & 45.7 & 49.3 & 20.2 & 30.5 & 48.0 & 11.5 & 40.5 \\
\addlinespace
\bfseries Race\\
White & 59.8 & 3.0 & 37.2 & 50.8 & 7.8 & 41.3 & 64.5 & 5.1 & 30.4 &  58.7 & 4.6 & 36.7  \\
Black & 38.7 & 13.1 & 48.2 & 22.2 &34.9& 43.0 & 31.0 & 44.5 & 24.5 & 32.5 & 26.3 &41.2\\
Coloured & 49.8 & 7.4 & 42.8 & 36.4 & 21.9 & 41.6 & 40.2 & 30.6 & 29.2 & 44.5 & 16.1 & 39.5   \\
Indian/Asian & 48.9  & 7.9 & 43.3 & 32.7 & 20.5 & 46.9 & 32.7 & 20.5 & 46.9 & 44.6 & 13.3 & 42.1\\
\addlinespace
\multicolumn{4}{l}{\bfseries Financial Aid}\\
Ineligible& 52.1  & 5.5  & 42.4 & 38.0 & 17.7 & 44.3 & 38.0 & 17.7 & 44.3 & 48.7 & 10.6 & 40.7  \\
Eligible & 40.7 & 17.2 & 42.1 & 26.5 & 37.5 & 36.1 & 33.8 & 42.9 & 23.3 & 35.2 & 30.3 & 34.5 \\
\addlinespace
\multicolumn{4}{l}{\bfseries Programme}\\
Mainstream  & 55.4  & 5.7 & 38.9 & 40.5 & 17.3 & 42.3 & 54.3 & 16.4 & 29.3 & 51.3 & 10.8 & 37.9  \\
Academic Dev. & 32.5 & 13.7 & 53.8 & 14.1 & 41.4 & 44.5 & 25.3 & 51.8 & 22.8 & 27.1 & 28.7 & 44.2 \\
\addlinespace
\multicolumn{4}{l}{\bfseries English Home Language}\\
Yes  & 55.1 & 4.9 & 39.9 & 44.1 & 13.3 & 42.6 & 56.3 & 14.1 & 29.6 & 52.8 & 8.6 & 38.6 \\
No & 38.8 & 13.4  & 47.8 & 22.3 &  35.0 & 42.7 & 32.7 & 42.7 & 24.6 & 32.8 & 26.6 & 40.6 \\
\addlinespace
\multicolumn{4}{l}{\bfseries School Quintile}\\
1  & 34.6 & 30.8 & 34.6 & 14.1 & 49.3 & 36.6 & 34.0 & 45.3 & 20.8 & 26.1 & 42.6 & 31.3  \\
2  & 30.2 & 16.0 & 53.8 & 25.6 & 36.4 & 38.0 & 28.8 & 50.9 & 20.3 & 28.1 & 35.1 & 36.8 \\
3  & 32.0 & 17.5 & 50.5 & 21.7 & 41.9 & 36.5 & 30.0 & 45.8 & 24.2 & 27.7 & 35.3 & 37.0 \\
4  & 37.7 & 17.7 & 44.5 & 17.7 & 38.0 & 44.3 & 30.0 & 46.7 & 23.3 & 29.5 & 32.0 & 38.5 \\
5  & 52.0 & 6.9 & 41.1 & 41.0 & 16.2 & 42.9 & 54.3 & 14.8 & 31.0 & 49.2 & 12.0 & 38.9  \\
Independent  & 52.5 & 5.3 & 42.2 & 40.7 & 13.9 & 45.5 & 54.3 &14.8 & 31.0 & 50.4 & 8.6 & 41.0 \\
\addlinespace
\multicolumn{4}{l}{\bfseries Western cape province}\\
Yes & 55.1 & 5.9 &39.0 & 42.1 &16.2 &41.7 & 52.0 &20.0 & 28.0 & 51.3 & 11.6 &37.0 \\
No &46.8 & 8.6 & 44.6 & 31.6 & 25.1 & 43.3 & 41.5 & 31.5 & 27.1 & 41.9 & 17.2 &41.0\\
\addlinespace
\multicolumn{4}{l}{\bfseries Year of First Registration} \\
{2006} &  87.8 & 11.3 & 0.9 & 70.3 & 29.0 & 0.7 & 69.5 & 28.2 & 2.3 & 79.9 & 18.9 &1.2  \\
{2007} & 88.2 & 10.1 &  1.7 & 68.7 & 30.0 & 1.4 & 68.5 & 30.8 & 0.7 & 79.4 &19.2 &1.4\\
{2008} & 87.1 & 10.3 &  2.6 & 63.6 & 30.6 & 5.8 & 66.2 & 32.3 & 1.6 & 76.7 & 20.3 & 3.0 \\
{2009} & 80.9 & 9.7 & 9.4 & 51.2   & 32.3 &16.5 & 51.9 & 43.9 & 4.2 & 64.9 & 24.9 & 10.2 \\
{2010} & 62.6 & 6.4 & 31.1 & 36.8 & 19.0 & 44.2 & 69.8 & 21.0 & 9.3 & 57.5 & 12.7 & 29.8 \\
{2011} & 15.8 & 7.2 & 77.0 & 0.0 & 18.2  & 81.8 & 37.3 & 23.4 & 39.8 & 15.3 & 12.8 & 71.9 \\
{2012} & 0.0 & 5.4 & 94.6 &  0.0 & 7.5 & 92.5 & 0.0 & 13.4 & 86.6 & 0.0 & 7.5 & 92.5 \\
{2013} & 0.0 & 1.7 & 98.3 & 0.0 & 4.9  & 95.1 & 0.0 & 5.1  & 94.9 & 0.0 & 3.0 & 97.0 \\
\end{tabular}
\end{table}
\end{document}

相关内容