长表中的标题段落、对齐方式和列大小

长表中的标题段落、对齐方式和列大小

如何在标题下方和下表的 toprule 之前添加标题段落?当我使用 \multicolumn 并添加段落时,它似乎不起作用。我之前使用过 \table 和 \tabular,可以将段落放在 \tabular 命令之前,但现在我需要使用 longtable,因为我正在使用 siunitx 对齐小数,所以我不能将表格放在框中。

如何将表格放入下面的页面宽度并指定列宽以改善布局?我想将 AAA、BBB、CCC、DDD 列等距分布,但四组之间留有空格,以便于阅读。

当我使用 \footnotesize 宏时,它也会影响标题和文本段落,是吗?此外,由于使用了 \footnotesize 宏,最后一段文本的大小似乎也减小了。

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

答案1

我认为这就是你想要的。表格材料仍然太宽。你可以使用\scriptsize或简单地将整个表格旋转到横向。

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

\scriptsize这是用于表格和描述材料的屏幕截图:

在此处输入图片描述

答案2

应该不是{\footnotesize...\footnotesize{...您可以使用

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

针对目标行。此外,该S列还将与其他tabular列配合使用。因此,如果您的表格较短,最好避免使用,longtable以便您可以调整其大小。

以下是使用居中表的尝试:

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

在此处输入图片描述

以及调整大小的表格:

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

在此处输入图片描述

相关内容