2

How can I add a heading paragraph below the title and before the toprule on the table below? When I use \multicolumn and add a paragraph, it doesn't seem to work. I used \table and \tabular before and could put the paragraph before the \tabular command, but I now need to use a longtable as I'm aligning decimals with siunitx, so I can't put the table in a box.

How can I fit the table into the page width below and specify column widths to improve the layout? I would like to equally space out the AAA, BBB, CCC, DDD columns, but have a space between the four groups to make it easier to read.

When I use the \footnotesize macro, it affects the title and the paragraph of text also, does it? Also, the size of the text in the last paragraph seems to be reduced due to the \footnotesize macro.

\documentclass[oneside,12pt]{article}

%tables
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{siunitx} %align numbers by decimal point
\usepackage{lipsum}
\begin{document}

\sisetup{table-format = -1.2}

\setlength{\tabcolsep}{2pt}
\lipsum[1]
\footnotesize{
\begin{longtable}{
l 
S[table-format = <1.3]
S[table-format = <1.3]
S[table-format = <1.3]@{\hskip 0.2cm}
S[table-format = <1.3]
S[table-format = <1.3]
S[table-format = <1.3] @{\hskip 0.2cm}
S[table-format = <1.3]
S[table-format = <1.3]
S[table-format = <1.3]@{\hskip 0.2cm}
S[table-format = <1.3]
S[table-format = <1.3]
S[table-format = <1.3]}

\caption[Table title]{Table title} \label{treeSummary} \\
    \multicolumn{13}{s}{\lipsum[1]}  \\
\toprule
& \multicolumn{6}{c}{First Group}                                 & \multicolumn{6}{c}{Second Group} \\
& \multicolumn{3}{c}{AB}  & \multicolumn{3}{c}{CD} & \multicolumn{3}{c}{EF} & \multicolumn{3}{c}{GH}\\
\midrule
 & \multicolumn{1}{c}{AAA} & \multicolumn{1}{c}{AAA} & \multicolumn{1}{c}{AAA}  & \multicolumn{1}{c}{BBB} & \multicolumn{1}{c}{BBB} & \multicolumn{1}{c}{BBB} & \multicolumn{1}{c}{CCC} & \multicolumn{1}{c}{CCC} & \multicolumn{1}{c}{CCC} & \multicolumn{1}{c}{DDD} & \multicolumn{1}{c}{DDD} &  \multicolumn{1}{c}{DDD}      \\
One         &    2.72  &     1.11  &     0.163 &     1.03  &     1.70   &    0.087 &     0.18  &     0.11  &     {$<$}0.001     &    0.47  &     1.14  &     0.063 \\
Two         &    1.65  &     2.62  &     0.084 &     1.37  &     1.38  &     0.095 &     0.11  &     0.14  &     0.124 &     0.54  &     0.58  &     0.174 \\
Three           &    2.39  &     1.57  &     0.331 &     1.77  &     1.95  &     0.007 &     0.83  &     0.24  &     {$<$}0.001     &    1.18  &     1.07  &     0.004 \\
Four        &    1.05  &     {--}   &       {--}   &     2.72  &     2.99  &     0.144 &     0.07  &     {--}   &    {--}      &     1.67  &     1.40   &   {$<$}0.009 \\
\noalign{\vskip 5pt}   
Sum     &    0.660 &     0.004 &           &     {$<$}0.001 &    0.245 &           &     {$<$}0.001 &    {$<$}0.001 &          &    {$<$}0.001 &     0.010 &        \\
\bottomrule
\end{longtable}
}
\lipsum[1]
\end{document}
  • If the table is short, why longtable? – user11232 Dec 18 '13 at 13:24
  • I need to use it so I can use \usepackage{siunitx} to align decimals. There's a few issues with it that I haven't resolved yet i.e. no \vspace allowed in the table. – user2146441 Dec 18 '13 at 13:27
  • 1
    siunitx can be used without longtable too. At present your table is too wide and using longtable will impose restrictions to resize it. – user11232 Dec 18 '13 at 13:29
  • What do I need to edit in the example above to move it to a regular table environment? If I just change the code from longtable to table, there are errors. Is there a way to specify individual column widths using an alternative table environment? – user2146441 Dec 18 '13 at 13:30
2

I think this is what you are going for. The tabular material is still too wide. You could use \scriptsize or simply rotate the whole table to landscape.

\documentclass[oneside,12pt]{article}

%tables
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{siunitx} %align numbers by decimal point
\sisetup{table-format = -1.2}
\usepackage{lipsum}
\begin{document}


\lipsum[1]

\begin{table}
\setlength{\tabcolsep}{2pt}
%this length is now bounded to this
%(and only this) table. If you want to change it globally, put it
%in your preamble
%   \footnotesize
    \scriptsize
\caption[Wombat title]{Wombat title} \label{treeSummary}
\lipsum[1]
    \centering
\begin{tabular}{
l 
S[table-format = <1.3]
S[table-format = <1.3]
S[table-format = <1.3]@{\hskip 0.2cm}
S[table-format = <1.3]
S[table-format = <1.3]
S[table-format = <1.3] @{\hskip 0.2cm}
S[table-format = <1.3]
S[table-format = <1.3]
S[table-format = <1.3]@{\hskip 0.2cm}
S[table-format = <1.3]
S[table-format = <1.3]
S[table-format = <1.3]
}
\toprule
& \multicolumn{6}{c}{First Group}                                 & \multicolumn{6}{c}{Second Group} \\
\cmidrule(lr){2-7}
\cmidrule(lr){8-13}
& \multicolumn{3}{c}{AB}  & \multicolumn{3}{c}{CD} & \multicolumn{3}{c}{EF} & \multicolumn{3}{c}{GH}\\
\midrule
 & \multicolumn{1}{c}{AAA} & \multicolumn{1}{c}{AAA} & \multicolumn{1}{c}{AAA}  & \multicolumn{1}{c}{BBB} & \multicolumn{1}{c}{BBB} & \multicolumn{1}{c}{BBB} & \multicolumn{1}{c}{CCC} & \multicolumn{1}{c}{CCC} & \multicolumn{1}{c}{CCC} & \multicolumn{1}{c}{DDD} & \multicolumn{1}{c}{DDD} &  \multicolumn{1}{c}{DDD}      \\
One  & 2.72 &  1.11 &  0.163 &  1.03 &  1.70 & 0.087 &  0.18 &  0.11 &  {$<$}0.001  & 0.47 &  1.14 &  0.063 \\
Two  & 1.65 &  2.62 &  0.084 &  1.37 &  1.38 &  0.095 &  0.11 &  0.14 &  0.124 &  0.54 &  0.58 &  0.174 \\
Three   & 2.39 &  1.57 &  0.331 &  1.77 &  1.95 &  0.007 &  0.83 &  0.24 &  {$<$}0.001  & 1.18 &  1.07 &  0.004 \\
Four  & 1.05 &  {--} &  {--} &  2.72 &  2.99 &  0.144 &  0.07 &  {--} & {--} &  1.67 &  1.40 & {$<$}0.009 \\
\noalign{\vskip 5pt} 
Sum  & 0.660 &  0.004 &   &  {$<$}0.001 & 0.245 &   &  {$<$}0.001 & {$<$}0.001 &  & {$<$}0.001 &  0.010 &  \\
\bottomrule
\end{tabular}
\end{table}

\lipsum[1]
\end{document}

This is a screenshot using \scriptsize for the tabular and the describing material:

enter image description here

  • Great stuff. If it's now back in the table/tabular environment, can I just put it in a scalebox to reduce the size, or will that affect the rendering of the characters? – user2146441 Dec 18 '13 at 13:54
  • You can scale it, but scaling always affects the rendering. Think about a text in footnotesize, if you scale it up so you can see it from 3 meters apart, it will just look ugly. But it is your decision. – Johannes_B Dec 18 '13 at 13:56
1

It should be {\footnotesize... not \footnotesize{.... You can use

\multicolumn{13}{@{}c@{}}{%
    \begin{minipage}{\linewidth}
    \lipsum[1]
    \end{minipage}}

for the intended row. Further, the S column will work with other tabulars also. Hence if your table is short, better avoid longtable so that you can resize it.

Here is an attempt with centred table:

\documentclass[oneside,12pt]{article}

%tables
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{siunitx} %align numbers by decimal point
\usepackage{lipsum}
\begin{document}

\sisetup{table-format = -1.2}

\setlength{\tabcolsep}{0pt}
\lipsum[1]

\begin{table}[h]
\centering
\caption[Table title]{Table title} \label{treeSummary}
\makebox[0pt]{\footnotesize
\begin{tabular}{
l
S[table-format = <1.3]@{}
S[table-format = <1.3]@{}
S[table-format = <1.3]@{\hskip 0.2cm}
S[table-format = <1.3]@{}
S[table-format = <1.3]@{}
S[table-format = <1.3] @{\hskip 0.2cm}
S[table-format = <1.3]@{}
S[table-format = <1.3]@{}
S[table-format = <1.3]@{\hskip 0.2cm}
S[table-format = <1.3]@{}
S[table-format = <1.3]@{}
S[table-format = <1.3]@{}}

    \multicolumn{13}{@{}c@{}}{%
\begin{minipage}{\linewidth}
\lipsum[1]
\end{minipage}}\\
\toprule
& \multicolumn{6}{c}{First Group}                                 & \multicolumn{6}{c}{Second Group} \\
& \multicolumn{3}{c}{AB}  & \multicolumn{3}{c}{CD} & \multicolumn{3}{c}{EF} & \multicolumn{3}{c}{GH}\\
\midrule
 & \multicolumn{1}{c}{AAA} & \multicolumn{1}{c}{AAA} & \multicolumn{1}{c}{AAA}  & \multicolumn{1}{c}{BBB} & \multicolumn{1}{c}{BBB} & \multicolumn{1}{c}{BBB} & \multicolumn{1}{c}{CCC} & \multicolumn{1}{c}{CCC} & \multicolumn{1}{c}{CCC} & \multicolumn{1}{c}{DDD} & \multicolumn{1}{c}{DDD} &  \multicolumn{1}{c}{DDD}      \\

One         &    2.72  &     1.11  &     0.163 &     1.03  &     1.70   &    0.087 &     0.18  &     0.11  &     {$<$}0.001     &    0.47  &     1.14  &     0.063 \\
Two         &    1.65  &     2.62  &     0.084 &     1.37  &     1.38  &     0.095 &     0.11  &     0.14  &     0.124 &     0.54  &     0.58  &     0.174 \\
Three           &    2.39  &     1.57  &     0.331 &     1.77  &     1.95  &     0.007 &     0.83  &     0.24  &     {$<$}0.001     &    1.18  &     1.07  &     0.004 \\
Four        &    1.05  &     {--}   &       {--}   &     2.72  &     2.99  &     0.144 &     0.07  &     {--}   &    {--}      &     1.67  &     1.40   &   {$<$}0.009 \\
\noalign{\vskip 5pt}
Sum     &    0.660 &     0.004 &           &     {$<$}0.001 &    0.245 &           &     {$<$}0.001 &    {$<$}0.001 &          &    {$<$}0.001 &     0.010 &        \\

\bottomrule
\end{tabular}
}
\end{table}

\lipsum[1]
\end{document}

enter image description here

And a resized table:

\documentclass[oneside,12pt]{article}

%tables
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{siunitx} %align numbers by decimal point
\usepackage{lipsum}
\usepackage{graphicx}   %% provides \resizebox macro
\begin{document}

\sisetup{table-format = -1.2}

%\setlength{\tabcolsep}{0pt}
\lipsum[1]
\begin{table}[h]
\caption[Table title]{Table title} \label{treeSummary} 
\resizebox{\textwidth}{!}{%
\begin{tabular}{%
l
S[table-format = <1.3]
S[table-format = <1.3]
S[table-format = <1.3]@{\hskip 0.2cm}
S[table-format = <1.3]
S[table-format = <1.3]
S[table-format = <1.3] @{\hskip 0.2cm}
S[table-format = <1.3]
S[table-format = <1.3]
S[table-format = <1.3]@{\hskip 0.2cm}
S[table-format = <1.3]
S[table-format = <1.3]
S[table-format = <1.3]}

\multicolumn{13}{@{}c@{}}{%
\begin{minipage}{1.5\linewidth}
\lipsum[1]
\end{minipage}}\\
\toprule
& \multicolumn{6}{c}{First Group}                                 & \multicolumn{6}{c}{Second Group} \\
& \multicolumn{3}{c}{AB}  & \multicolumn{3}{c}{CD} & \multicolumn{3}{c}{EF} & \multicolumn{3}{c}{GH}\\
\midrule
 & \multicolumn{1}{c}{AAA} & \multicolumn{1}{c}{AAA} & \multicolumn{1}{c}{AAA}  & \multicolumn{1}{c}{BBB} & \multicolumn{1}{c}{BBB} & \multicolumn{1}{c}{BBB} & \multicolumn{1}{c}{CCC} & \multicolumn{1}{c}{CCC} & \multicolumn{1}{c}{CCC} & \multicolumn{1}{c}{DDD} & \multicolumn{1}{c}{DDD} &  \multicolumn{1}{c}{DDD}      \\

One         &    2.72  &     1.11  &     0.163 &     1.03  &     1.70   &    0.087 &     0.18  &     0.11  &     {$<$}0.001     &    0.47  &     1.14  &     0.063 \\
Two         &    1.65  &     2.62  &     0.084 &     1.37  &     1.38  &     0.095 &     0.11  &     0.14  &     0.124 &     0.54  &     0.58  &     0.174 \\
Three           &    2.39  &     1.57  &     0.331 &     1.77  &     1.95  &     0.007 &     0.83  &     0.24  &     {$<$}0.001     &    1.18  &     1.07  &     0.004 \\
Four        &    1.05  &     {--}   &       {--}   &     2.72  &     2.99  &     0.144 &     0.07  &     {--}   &    {--}      &     1.67  &     1.40   &   {$<$}0.009 \\
\noalign{\vskip 5pt}
Sum     &    0.660 &     0.004 &           &     {$<$}0.001 &    0.245 &           &     {$<$}0.001 &    {$<$}0.001 &          &    {$<$}0.001 &     0.010 &        \\

\bottomrule
\end{tabular}
}
\end{table}

\lipsum[1]
\end{document}

enter image description here

  • I don't recommend to place the lipsum paragraph (or whatever) inside a multicolumn and into the tabular if it doesn't belong there. Look at the vertical spacing, it is very small (text to caption, and text to toprule). – Johannes_B Dec 18 '13 at 14:23
  • It is the same font size, if put in the table environment. – Johannes_B Dec 18 '13 at 14:33
  • My apologies, i wasn't aware of your resizing. But i still think, that resizing something isn't a good idea in most cases. – Johannes_B Dec 18 '13 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.