![使用 siunitx 包格式化 Longtable](https://linux22.com/image/407286/%E4%BD%BF%E7%94%A8%20siunitx%20%E5%8C%85%E6%A0%BC%E5%BC%8F%E5%8C%96%20Longtable.png)
我正在使用以下脚本来创建我的表:
\sisetup{parse-numbers = false}
\begin{longtable}{ @{} l *{ 9 }{S[table-format = +2.3 ]} @{}}
\caption{\label{tab:}Results}\\
\toprule
\multicolumn{1}{c}{ } & \multicolumn{3}{c}{AAAAAAAAA} & \multicolumn{3}{c}{BBBBBBBBB} & \multicolumn{3}{c}{CCCCCCCCC} \\
\cmidrule(l{3pt}r{3pt}){2-4} \cmidrule(l{3pt}r{3pt}){5-7} \cmidrule(l{3pt}r{3pt}){8-10}
{Date} & {XXX} & {YYY} & {ZZZ} & {XXX} & {YYY} & {ZZZ} & {XXX} & {YYY} & {ZZZ}\\
\midrule
\endfirsthead
\caption[]{Results \textit{(continued)}}\\
\toprule
\multicolumn{1}{c}{ } & \multicolumn{3}{c}{AAAAAAAAA} & \multicolumn{3}{c}{BBBBBBBBB} & \multicolumn{3}{c}{CCCCCCCCC} \\
\cmidrule(l{3pt}r{3pt}){2-4} \cmidrule(l{3pt}r{3pt}){5-7} \cmidrule(l{3pt}r{3pt}){8-10}
{Date} & {XXX} & {YYY} & {ZZZ} & {XXX} & {YYY} & {ZZZ} & {XXX} & {YYY} & {ZZZ}\\
\midrule
\endhead
\
\endfoot
\bottomrule
\endlastfoot
\addlinespace
2000-06-11 & -0.010 & -0.010 & -0.990 & -0.020 & -0.020 & -1.768 & -0.024 & -0.024 & -2.057\\
2000-06-12 & 0.010 & 0.000 & 0.968 & 0.022 & 0.001 & 1.859 & 0.022 & -0.002 & 1.904\\
2000-06-13 & 0.000 & 0.000 & 0.040 & 0.000 & 0.001 & 0.042 & 0.001 & -0.001 & 0.118\\
\end{longtable}
输出还不错,但我认为列名没有以其值居中,并且我还想减少每组列之间的空间(XXX,YYY,ZZZ)有人可以帮我解决这两个问题吗?
答案1
像这样?
\documentclass{article}
\usepackage{geometry}
\usepackage{siunitx} % <---
\usepackage{booktabs, longtable}
\usepackage{xparse}
\NewExpandableDocumentCommand\mcc{O{1}m}
{\multicolumn{#1}{c}{#2}}
\begin{document}
\begin{longtable}{ @{} l *{9}{S[table-format=-1.3]} @{} }
\caption{\label{tab:}Results}\\
\toprule
\mcc{} & \mcc[3]{AAAAAAAAA} & \mcc[3]{BBBBBBBBB} & \mcc[3]{CCCCCCCCC} \\
\cmidrule(lr){2-4} \cmidrule(lr){5-7} \cmidrule(l){8-10}
Date & {XXX} & {YYY} & {ZZZ} & {XXX} & {YYY} & {ZZZ} & {XXX} & {YYY} & {ZZZ} \\
\midrule
\endfirsthead
\caption[]{Results \textit{(continued)}}\\
\toprule
\mcc{} & \mcc[3]{AAAAAAAAA} & \mcc[3]{BBBBBBBBB} & \mcc[3]{CCCCCCCCC} \\
\cmidrule(lr){2-4} \cmidrule(lr){5-7} \cmidrule(l){8-10}
Date & {XXX} & {YYY} & {ZZZ} & {XXX} & {YYY} & {ZZZ} & {XXX} & {YYY} & {ZZZ} \\
\midrule
\endhead
\endfoot
\bottomrule
\endlastfoot
% \addlinespace
2000-06-11 & -0.010 & -0.010 & -0.990 & -0.020 & -0.020 & -1.768 & -0.024 & -0.024 & -2.057\\
2000-06-12 & 0.010 & 0.000 & 0.968 & 0.022 & 0.001 & 1.859 & 0.022 & -0.002 & 1.904\\
2000-06-13 & 0.000 & 0.000 & 0.040 & 0.000 & 0.001 & 0.042 & 0.001 & -0.001 & 0.118\\
\end{longtable}
\end{document}
附录 如果您希望组之间有更多空间,您可以简单地在它们之间插入空列:
\documentclass{article}
\usepackage{geometry}
\usepackage{siunitx} % <---
\usepackage{booktabs, longtable}
\usepackage{xparse}
\NewExpandableDocumentCommand\mcc{O{1}m}
{\multicolumn{#1}{c}{#2}}
\begin{document}
\begin{longtable}{ @{} l *{3}{S[table-format=-1.3]} c
*{3}{S[table-format=-1.3]} c
*{3}{S[table-format=-1.3]} @{} }
\caption{\label{tab:}Results}\\
\toprule
\mcc{} & \mcc[3]{AAAAAAAAA} && \mcc[3]{BBBBBBBBB} && \mcc[3]{CCCCCCCCC} \\
\cmidrule(lr){2-4} \cmidrule(lr){6-8} \cmidrule(l){10-12}
Date & {XXX} & {YYY} & {ZZZ} && {XXX} & {YYY} & {ZZZ} && {XXX} & {YYY} & {ZZZ} \\
\midrule
\endfirsthead
\caption[]{Results \textit{(continued)}}\\
\toprule
\mcc{} & \mcc[3]{AAAAAAAAA} && \mcc[3]{BBBBBBBBB} && \mcc[3]{CCCCCCCCC} \\
\cmidrule(lr){2-4} \cmidrule(lr){5-7} \cmidrule(l){8-10}
Date & {XXX} & {YYY} & {ZZZ} && {XXX} & {YYY} & {ZZZ} && {XXX} & {YYY} & {ZZZ} \\
\midrule
\endhead
\endfoot
\bottomrule
\endlastfoot
% \addlinespace
2000-06-11
& -0.010 & -0.010 & -0.990 && -0.020 & -0.020 & -1.768 && -0.024 & -0.024 & -2.057\\
2000-06-12
& 0.010 & 0.000 & 0.968 && 0.022 & 0.001 & 1.859 && 0.022 & -0.002 & 1.904\\
2000-06-13
& 0.000 & 0.000 & 0.040 && 0.000 & 0.001 & 0.042 && 0.001 & -0.001 & 0.118\\
\end{longtable}
\end{document}