1

I am using the following script to create my table:

\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}

Output enter image description here

the output is not bad, but I think the column names are not centered with their values, and I also want to reduce the space between the columns in each group (XXX, YYY, ZZZ) can someone please help me with these two issues?

2
  • As always on the site you are much much more likely to get help if you provide a full (but minimal) self contained example including preamble and document class instead of posting a sniplet where we have to guess the rest.
    – daleif
    Commented Jan 30, 2020 at 16:26
  • 1
    It will fit better if you do two things: (1) re-enable the number parsing, (2) specify the columns correctly, I'd use -1.3 not +2.3
    – daleif
    Commented Jan 30, 2020 at 16:29

1 Answer 1

1

Like this?

enter image description here

\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}

Addendum If you like to have more space between groups you can simply insert emty columns between them:

\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}

enter image description here

4
  • It looks better regarding that the columns are centering the values. The second issue was that I am trying to bring (XXX, YYY and ZZZ) a little bit closer to each other within each group. Or alternatively, make more space between the three groups (AA..., BB... and CC...) Commented Jan 30, 2020 at 16:54
  • @Kingindanord, just insert empty columns between groups. See edited answer
    – Zarko
    Commented Jan 30, 2020 at 17:28
  • why now the "-" sign in "YYY" columns looks different? and it seems that "ZZZ" is further away Commented Jan 30, 2020 at 17:50
  • @Kingindanord, oh, there is mismatch in used columns. I will correct asap
    – Zarko
    Commented Jan 30, 2020 at 18:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .