格式化长表

格式化长表

我有一张长桌,但我不确定如何做下面列出的两件事。

注意:本文底部给出的 MWE 并非表格在我的文档中的准确表示。这是因为我使用的是模板,它有很多设置。因此不必担心列宽或其他问题。当我使用模板时,它们显示正确,但在 MWE 中则不正确。我只关心下面列出的两个问题

(1) 您会注意到某些括号内的数字 (...) 紧挨着“较大”的数字(例如,查看“白人”行和“学术排除”列或“主流”行和“学术排除”列)。我怀疑这个问题与小数对齐有关,因为只有当较大的数字有一个数字时才会出现问题小数点。但是,我不确定如何解决这个问题。

(2)“命令”(即我这样做(我无法与他争论)的方法是,在“样本中个人比例”列和“已毕业”列之间设置一条垂直线/规则。我在这里注意到,垂直规则在这里是不受欢迎的,不应该与书本标签一起使用,但不幸的是,我没有其他选择。

在此处输入图片描述

\documentclass{article}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{siunitx}
\begin{document}
\noindent\begin{longtable}{>{\raggedright\arraybackslash}p{.17\textwidth}*{4}{S}}% don't use vertical rules with booktabs (see the documentation)
\caption {Descriptive Statistics (\%): Commerce Faculty ($N = \num{6 508}$)}
    \label{table:DSCF} \\
\toprule
{\bfseries\hskip0pt Variable} & \multicolumn{1}{p{.17\textwidth}}{\bfseries\hskip0pt Proportion of Individuals in Sample} & \multicolumn{1}{p{.15\textwidth}}{\bfseries\hskip0pt Graduated} & \multicolumn{1}{p{.17\textwidth}}{\bfseries\hskip0pt Academically Excluded} & \multicolumn{1}{p{.12\textwidth}}{\bfseries\hskip0pt Censored}\\
    \midrule
\endfirsthead
    {\bfseries\hskip0pt Variable} & \multicolumn{1}{p{.17\textwidth}}{\bfseries\hskip0pt Proportion of Individuals in Sample} & \multicolumn{1}{p{.15\textwidth}}{\bfseries\hskip0pt Graduated} & \multicolumn{1}{p{.17\textwidth}}{\bfseries\hskip0pt Academically Excluded} & \multicolumn{1}{p{.12\textwidth}}{\bfseries\hskip0pt Censored} \\
    \midrule
    \endhead
    \bottomrule
    \endlastfoot
\bfseries Total & 100.0 & 50.1 \footnotesize{(45.8)} & 7.5 \footnotesize{(14.9)} & 42.4 \footnotesize{(39.3)}  \\
\addlinespace
\bfseries Gender\\
Male                 & 52.4 & 49.6 \footnotesize{(44.3)} & 8.7 \footnotesize{(17.3)}  & 41.7 \footnotesize{(38.5)} \\
Female               & 47.6 & 50.7 \footnotesize{(48.0)} & 6.2 \footnotesize{(11.5)} & 43.1 \footnotesize{(40.5)}\\
\addlinespace
\bfseries Race\\
White & 40.3 & 59.8 \footnotesize{(58.7)} & 3.0 \footnotesize{(4.6)} & 37.2 \footnotesize{(36.7)}\\
Black & 32.4 & 38.7 \footnotesize{(32.5)} & 13.1 \footnotesize{(26.3)} & 48.2 \footnotesize{(41.2)}\\
Coloured & 13.0 & 49.8 \footnotesize{(44.5)} & 7.4 \footnotesize{(16.1)} & 42.8 \footnotesize{(39.5)}\\
Indian/Asian & 14.3 & 48.9 \footnotesize{(44.6)} & 7.9 \footnotesize{(13.3)} & 43.3 \footnotesize{(42.1)}\\
\addlinespace
\bfseries Financial Aid\\
Ineligible for Financial Aid & 82.3 & 52.1 \footnotesize{(48.7)} & 5.5 \footnotesize{(10.6)} & 42.4 \footnotesize{(40.7)} \\
Eligible for Financial Aid & 17.7 & 40.7 \footnotesize{(35.2)} & 17.2 \footnotesize{(30.3)} & 42.1 \footnotesize{(34.5)} \\
\addlinespace
\bfseries Programme\\
Mainstream & 76.9 & 55.4 \footnotesize{(51.3)} & 5.7 \footnotesize{(10.8)} & 38.9 \footnotesize{(37.9)} \\
Academic Development & 23.1 & 32.5 \footnotesize{(27.1)} & 13.7 \footnotesize{(28.7)} & 53.8 \footnotesize{(44.2)} \\
\addlinespace
\bfseries English Home Language\\
Yes & 69.3 & 55.1 \footnotesize{(52.8)} & 4.9 \footnotesize{(8.6)} & 39.9 \footnotesize{(38.6)}\\
No & 30.7 & 38.8 \footnotesize{(32.8)} & 13.4 \footnotesize{(26.6)} & 47.8 \footnotesize{(40.6)}\\
\addlinespace
\bfseries School Quintile\\
1 & 0.8 & 34.6 \footnotesize{(26.1)} & 30.8 \footnotesize{(42.6)} & 34.6 \footnotesize{(31.3)} \\
2 & 1.6 & 30.2 \footnotesize{(28.1)} & 16.0 \footnotesize{(35.1)} & 53.8 \footnotesize{(36.8)} \\
3 & 5.0 & 32.0 \footnotesize{(27.7)} & 17.5 \footnotesize{(35.3)} & 50.5 \footnotesize{(37.0)} \\
4 & 4.1 & 37.7 \footnotesize{(29.5)} & 17.7 \footnotesize{(32.0)} & 44.5 \footnotesize{(38.5)} \\
5 & 45.4 & 52.0 \footnotesize{(49.2)} & 6.9 \footnotesize{(12.0)} & 41.1 \footnotesize{(38.9)} \\
Independent  & 43.1 & 52.5 \footnotesize{(50.4)} & 5.3 \footnotesize{(8.6)} & 42.2 \footnotesize{(41.0)} \\
\addlinespace
{\bfseries Province}\\
Western Cape & 40.0 & 55.1 \footnotesize{(51.3)} &5.9 \footnotesize{(11.6)} &39.0 \footnotesize{(37.0)}\\
Non-Western Cape & 59.9 & 46.8 \footnotesize{(41.9)} & 8.6 \footnotesize{(17.2)} & 44.6 \footnotesize{(41.0)}\\
\addlinespace
{\bfseries Year of First Registration} \\
{2006} & 11.6  & 87.8 \footnotesize{(79.9)} & 11.3 \footnotesize{(18.9)} & 0.9 \footnotesize{(1.2)}\\
{2007} & 11.9 & 88.2 \footnotesize{(79.4)} & 10.1 \footnotesize{(19.2)}   & 1.7 \footnotesize{(1.4)}\\
{2008} & 12.6 & 87.1 \footnotesize{(76.7)} & 10.3 \footnotesize{(20.3)} & 2.6 \footnotesize{(3.0)}\\
{2009} & 11.9 & 80.9 \footnotesize{(64.9)} & 9.7 \footnotesize{(24.9)} & 9.4 \footnotesize{(10.2)}\\
{2010} & 11.1 & 62.6 \footnotesize{(57.5)} & 6.4 \footnotesize{(12.7)} & 31.1 \footnotesize{(29.8)}\\
{2011} & 11.7 & 15.8 \footnotesize{(15.3)} & 7.2 \footnotesize{(12.8)} & 77.0 \footnotesize{(71.9)}\\
{2012} & 14.1 & 0.0 \footnotesize{(0.0)}  & 5.4 \footnotesize{(7.5)} & 94.6 \footnotesize{(92.5)}\\
{2013} & 15.1 & 0.0 \footnotesize{(0.0)} & 1.7 \footnotesize{(3.0)} & 98.3 \footnotesize{(97.0)}\\
\end{longtable}
\end{document}

答案1

对于要求 2,我无法提供太多帮助,只能建议你在标题中提供更多结构,希望这样可以省去令人讨厌的垂直规则。(如果你必须添加垂直线,您可能需要用 替换\addlinespace说明,[1ex]以避免表格主体出现间隙。)

关于目标 1,我建议您为“常规”数字和括号中的数字设置单独的列。此建议与 David Carlisle 提供的答案中的建议类似,除了我建议S对所有数字列使用列类型。使用S列而不是c括号内数字的列的一个中等优势是数字将继续在小数点标记上对齐。

在此处输入图片描述

在此处输入图片描述

\documentclass{article}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{ragged2e}
\newcolumntype{C}[1]{>{\Centering\arraybackslash}p{#1}}
\begin{document}

\begin{longtable}{ 
  >{\RaggedRight\arraybackslash}p{.17\textwidth} 
  S 
  *{3}{S[table-format=2.1] >{\footnotesize}S[table-format=3.2,input-symbols=()]} }
\caption {Descriptive Statistics (\%): Commerce Faculty ($N = 6508$)}
\label{table:DSCF} \\
\toprule
{\bfseries Variable} & 
\multicolumn{1}{C{.17\textwidth}}{\bfseries Proportions in Sample} & 
\multicolumn{6}{c}{\bfseries Proportions by Subtype}\\
\cmidrule{3-8}
&&
\multicolumn{2}{C{.19\textwidth}}{\bfseries Graduated} & \multicolumn{2}{C{.19\textwidth}}{\bfseries Academically Excluded} & 
\multicolumn{2}{C{.19\textwidth}}{\bfseries Censored}\\
\midrule
\endfirsthead
{\bfseries Variable} & 
\multicolumn{1}{C{.17\textwidth}}{\bfseries Proportions in Sample} & 
\multicolumn{6}{c}{\bfseries Proportions by Subtypes}\\
\cmidrule{3-8}
&&
\multicolumn{2}{C{.19\textwidth}}{\bfseries Graduated} & \multicolumn{2}{C{.19\textwidth}}{\bfseries Academically Excluded} & 
\multicolumn{2}{C{.19\textwidth}}{\bfseries Censored}\\
\midrule
\endhead
\bottomrule
\endlastfoot
\bfseries Total & 100.0 & 50.1 & (45.8) & 7.5 & (14.9) & 42.4 & (39.3)  \\
\addlinespace
\bfseries Gender\\
Male                 & 52.4 & 49.6 & (44.3) & 8.7 & (17.3)  & 41.7 & (38.5) \\
Female               & 47.6 & 50.7 & (48.0) & 6.2 & (11.5) & 43.1 & (40.5)\\
\addlinespace
\bfseries Race\\
White & 40.3 & 59.8 & (58.7) & 3.0 & (4.6) & 37.2 & (36.7)\\
Black & 32.4 & 38.7 & (32.5) & 13.1 & (26.3) & 48.2 & (41.2)\\
Coloured & 13.0 & 49.8 & (44.5) & 7.4 & (16.1) & 42.8 & (39.5)\\
Indian/Asian & 14.3 & 48.9 & (44.6) & 7.9 & (13.3) & 43.3 & (42.1)\\
\addlinespace
\bfseries Financial Aid\\
Ineligible for Financial Aid & 82.3 & 52.1 & (48.7) & 5.5 & (10.6) & 42.4 & (40.7) \\
Eligible for Financial Aid & 17.7 & 40.7 & (35.2) & 17.2 & (30.3) & 42.1 & (34.5) \\
\addlinespace
\bfseries Programme\\
Mainstream & 76.9 & 55.4 & (51.3) & 5.7 & (10.8) & 38.9 & (37.9) \\
Academic Development & 23.1 & 32.5 & (27.1) & 13.7 & (28.7) & 53.8 & (44.2) \\
\addlinespace
\bfseries English Home Language\\
Yes & 69.3 & 55.1 & (52.8) & 4.9 & (8.6) & 39.9 & (38.6)\\
No & 30.7 & 38.8 & (32.8) & 13.4 & (26.6) & 47.8 & (40.6)\\
\addlinespace
\bfseries School Quintile\\
1 & 0.8 & 34.6 & (26.1) & 30.8 & (42.6) & 34.6 & (31.3) \\
2 & 1.6 & 30.2 & (28.1) & 16.0 & (35.1) & 53.8 & (36.8) \\
3 & 5.0 & 32.0 & (27.7) & 17.5 & (35.3) & 50.5 & (37.0) \\
4 & 4.1 & 37.7 & (29.5) & 17.7 & (32.0) & 44.5 & (38.5) \\
5 & 45.4 & 52.0 & (49.2) & 6.9 & (12.0) & 41.1 & (38.9) \\
Independent  & 43.1 & 52.5 & (50.4) & 5.3 & (8.6) & 42.2 & (41.0) \\
\addlinespace
{\bfseries Province}\\
Western Cape & 40.0 & 55.1 & (51.3) &5.9 & (11.6) &39.0 & (37.0)\\
Non-Western Cape & 59.9 & 46.8 & (41.9) & 8.6 & (17.2) & 44.6 & (41.0)\\
\addlinespace
{\bfseries Year of First Registration} \\
{2006} & 11.6  & 87.8 & (79.9) & 11.3 & (18.9) & 0.9 & (1.2)\\
{2007} & 11.9 & 88.2 & (79.4) & 10.1 & (19.2)   & 1.7 & (1.4)\\
{2008} & 12.6 & 87.1 & (76.7) & 10.3 & (20.3) & 2.6 & (3.0)\\
{2009} & 11.9 & 80.9 & (64.9) & 9.7 & (24.9) & 9.4 & (10.2)\\
{2010} & 11.1 & 62.6 & (57.5) & 6.4 & (12.7) & 31.1 & (29.8)\\
{2011} & 11.7 & 15.8 & (15.3) & 7.2 & (12.8) & 77.0 & (71.9)\\
{2012} & 14.1 & 0.0 & (0.0)  & 5.4 & (7.5) & 94.6 & (92.5)\\
{2013} & 15.1 & 0.0 & (0.0) & 1.7 & (3.0) & 98.3 & (97.0)\\
\end{longtable}
\end{document} 

答案2

在此处输入图片描述

\documentclass{article}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{siunitx,array}
\begin{document}

%\noindent no

\begin{longtable}{
>{\raggedright\arraybackslash}
p{.17\textwidth}S|
*{3}{S@{\,}>\footnotesize c}}% don't use vertical rules with booktabs (see the documentation)
\caption {Descriptive Statistics (\%): Commerce Faculty ($N = \num{6 508}$)}
    \label{table:DSCF} \\
\toprule
{\bfseries\hskip0pt Variable} & 
\multicolumn{1}{p{.17\textwidth}|}{\centering\bfseries\hskip0pt Proportion of Individuals in Sample} & 
\multicolumn{2}{p{.15\textwidth}}{\centering\bfseries\hskip0pt Graduated} &
 \multicolumn{2}{p{.17\textwidth}}{\centering\bfseries\hskip0pt Academically Excluded} & 
\multicolumn{2}{p{.12\textwidth}}{\centering\bfseries\hskip0pt Censored}\\
    \midrule
\endfirsthead
    {\bfseries\hskip0pt Variable} &
 \multicolumn{1}{p{.17\textwidth}|}{\centering\bfseries\hskip0pt Proportion of Individuals in Sample} &
 \multicolumn{2}{p{.15\textwidth}}{\centering\bfseries\hskip0pt Graduated} & 
\multicolumn{2}{p{.17\textwidth}}{\centering\bfseries\hskip0pt Academically Excluded} &
 \multicolumn{2}{p{.12\textwidth}}{\centering\bfseries\hskip0pt Censored} \\
    \midrule
    \endhead
    \bottomrule
    \endlastfoot
\bfseries Total & 100.0 & 50.1&{(45.8)} & 7.5&{(14.9)} & 42.4&{(39.3)}  \\
\addlinespace
\bfseries Gender&&&&&&&\\
Male                 & 52.4 & 49.6&{(44.3)} & 8.7&{(17.3)}  & 41.7&{(38.5)} \\
Female               & 47.6 & 50.7&{(48.0)} & 6.2&{(11.5)} & 43.1&{(40.5)}\\
\addlinespace
\bfseries Race&&&&&&&\\
White & 40.3 & 59.8&{(58.7)} & 3.0&{(4.6)} & 37.2&{(36.7)}\\
Black & 32.4 & 38.7&{(32.5)} & 13.1&{(26.3)} & 48.2&{(41.2)}\\
Coloured & 13.0 & 49.8&{(44.5)} & 7.4&{(16.1)} & 42.8&{(39.5)}\\
Indian/Asian & 14.3 & 48.9&{(44.6)} & 7.9&{(13.3)} & 43.3&{(42.1)}\\
\addlinespace
\bfseries Financial Aid&&&&&&&\\
Ineligible for Financial Aid & 82.3 & 52.1&{(48.7)} & 5.5&{(10.6)} & 42.4&{(40.7)} \\
Eligible for Financial Aid & 17.7 & 40.7&{(35.2)} & 17.2&{(30.3)} & 42.1&{(34.5)} \\
\addlinespace
\bfseries Programme&&&&&&&\\
Mainstream & 76.9 & 55.4&{(51.3)} & 5.7&{(10.8)} & 38.9&{(37.9)} \\
Academic Development & 23.1 & 32.5&{(27.1)} & 13.7&{(28.7)} & 53.8&{(44.2)} \\
\addlinespace
\bfseries English Home Language&&&&&&&\\
Yes & 69.3 & 55.1&{(52.8)} & 4.9&{(8.6)} & 39.9&{(38.6)}\\
No & 30.7 & 38.8&{(32.8)} & 13.4&{(26.6)} & 47.8&{(40.6)}\\
\addlinespace
\bfseries School Quintile&&&&&&&\\
1 & 0.8 & 34.6&{(26.1)} & 30.8&{(42.6)} & 34.6&{(31.3)} \\
2 & 1.6 & 30.2&{(28.1)} & 16.0&{(35.1)} & 53.8&{(36.8)} \\
3 & 5.0 & 32.0&{(27.7)} & 17.5&{(35.3)} & 50.5&{(37.0)} \\
4 & 4.1 & 37.7&{(29.5)} & 17.7&{(32.0)} & 44.5&{(38.5)} \\
5 & 45.4 & 52.0&{(49.2)} & 6.9&{(12.0)} & 41.1&{(38.9)} \\
Independent  & 43.1 & 52.5&{(50.4)} & 5.3&{(8.6)} & 42.2&{(41.0)} \\
\addlinespace
{\bfseries Province}&&&&&&&\\
Western Cape & 40.0 & 55.1&{(51.3)} &5.9&{(11.6)} &39.0&{(37.0)}\\
Non-Western Cape & 59.9 & 46.8&{(41.9)} & 8.6&{(17.2)} & 44.6&{(41.0)}\\
\addlinespace
{\bfseries Year of First Registration}&&&&&&&\\
{2006} & 11.6  & 87.8&{(79.9)} & 11.3&{(18.9)} & 0.9&{(1.2)}\\
{2007} & 11.9 & 88.2&{(79.4)} & 10.1&{(19.2)}   & 1.7&{(1.4)}\\
{2008} & 12.6 & 87.1&{(76.7)} & 10.3&{(20.3)} & 2.6&{(3.0)}\\
{2009} & 11.9 & 80.9&{(64.9)} & 9.7&{(24.9)} & 9.4&{(10.2)}\\
{2010} & 11.1 & 62.6&{(57.5)} & 6.4&{(12.7)} & 31.1&{(29.8)}\\
{2011} & 11.7 & 15.8&{(15.3)} & 7.2&{(12.8)} & 77.0&{(71.9)}\\
{2012} & 14.1 & 0.0&{(0.0)}  & 5.4&{(7.5)} & 94.6&{(92.5)}\\
{2013} & 15.1 & 0.0&{(0.0)} & 1.7&{(3.0)} & 98.3&{(97.0)}\\
\end{longtable}
\end{document}

相关内容