使用表格的 \hbox 过满问题

使用表格的 \hbox 过满问题

我想要得到这样的东西:在此处输入图片描述

我使用了以下代码:

\documentclass{article}
\usepackage{booktabs}
\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}
\begin{document}
\begin{table*}\centering
\ra{1.3}
\begin{tabular}{@{}rrrrcrrrcrrr@{}}
\toprule
& \multicolumn{3}{c}{$w = 8$} & 
\phantom{abc}& \multicolumn{3}{c}{$w = 16$} &
\phantom{abc} & \multicolumn{3}{c}{$w = 32$}\\
\cmidrule{2-4} \cmidrule{6-8} \cmidrule{10-12}
& $t=0$ & $t=1$ & $t=2$ && $t=0$ & $t=1$ & $t=2$ && $t=0$ & $t=1$ & $t=2$\\\midrule
$dir=1$\\
$c$ & 0.0790 & 0.1692 & 0.2945 && 0.3670 & 0.7187 & 3.1815 && -1.0032 & -1.7104 & -21.7969\\
$c$ & -0.8651& 50.0476& 5.9384&& -9.0714& 297.0923& 46.2143&& 4.3590& 34.5809& 76.9167\\
$c$ & 124.2756& -50.9612& -14.2721&& 128.2265& -630.5455& -381.0930&& -121.0518& -137.1210& -220.2500\\
$dir=0$\\
$c$ & 0.0357& 1.2473& 0.2119&& 0.3593& -0.2755& 2.1764&& -1.2998& -3.8202& -1.2784\\
$c$ & -17.9048& -37.1111& 8.8591&& -30.7381& -9.5952& -3.0000&& -11.1631& -5.7108& -15.6728\\
$c$ & 105.5518& 232.1160& -94.7351&& 100.2497& 141.2778& -259.7326&& 52.5745& 10.1098& -140.2130\\
\bottomrule
\end{tabular}
\caption{Caption}
\end{table*}
\end{document}

但我得到了:在此处输入图片描述

我不知道 \hbox 过满的问题是怎么发生的。

答案1

它将适合加载包的边距geometry,这使得边距更合理,将字体大小设置为footnotesize并减小\arraycolsep。顺便说一句,我用数组替换了表格环境,以获得更简单的代码。

\documentclass{article}
\usepackage{booktabs}
\usepackage[showframe, nomarginpar]{geometry}
\usepackage{amsmath}
\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}

\begin{document}

\begin{table*}\centering
  \ra{1.3}\setlength\arraycolsep{3.5pt}\footnotesize
  $ \begin{array}{rrrr@{\quad}rrr@{\quad}rrr}
  \toprule
  & \multicolumn{3}{c}{w = 8}& \multicolumn{3}{c}{w = 16} & \multicolumn{3}{c}{w = 32}\\
  \cmidrule(lr){2-4} \cmidrule(lr){5-7} \cmidrule(l){8-10}
  & t=0 & t=1 & t=2 & t=0 & t=1 & t=2 & t=0 & t=1 & t=2\\\midrule
  \text{dir}=1\\
  c & 0.0790 & 0.1692 & 0.2945 & 0.3670 & 0.7187 & 3.1815 & -1.0032 & -1.7104 & -21.7969\\
  c & -0.8651& 50.0476& 5.9384& -9.0714& 297.0923& 46.2143& 4.3590& 34.5809& 76.9167\\
  c & 124.2756& -50.9612& -14.2721& 128.2265& -630.5455& -381.0930& -121.0518& -137.1210& -220.2500\\
  \addlinespace
  \text{dir}=0\\
  c & 0.0357& 1.2473& 0.2119& 0.3593& -0.2755& 2.1764& -1.2998& -3.8202& -1.2784\\
  c & -17.9048& -37.1111& 8.8591& -30.7381& -9.5952& -3.0000& -11.1631& -5.7108& -15.6728\\
  c & 105.5518& 232.1160& -94.7351& 100.2497& 141.2778& -259.7326& 52.5745& 10.1098& -140.2130\\
  \bottomrule
  \end{array} $
  \caption{Caption}
\end{table*}

\end{document} 

在此处输入图片描述

答案2

这是另一个选项,它可以旋转表格而不是减小字体大小等。这还允许您保持最外列左侧和右侧的间距,我认为这在booktabs具有规则的布局中是必要的。

我又简化了几个方面。我删除了用于间隔的列,而是使用特定的跳过,加载包array。我还用它定义了一种新的列类型,将所有内容设置为数学,这样输入就更容易了。

我使用了此(lr)选项,\cmidrule这样这里的换行就无需额外的列。在表格右侧留出通常的间距也有助于打破内部规则,使其看起来更加平衡。

这可以在不减小字体大小或边距的情况下实现,尽管您可能出于其他原因希望调整页面布局以获得较小的边距,从而为您提供更大的灵活性。

\documentclass{article}
\usepackage{booktabs,rotating,array}
\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}
\newcolumntype{R}{>{$}r<{$}}
\begin{document}
  \begin{sidewaystable}
    \centering
    \ra{1.3}
    \begin{tabular}{*{4}{R}!{\hskip .4em}*{3}{R}!{\hskip .4em}*{3}{R}}
      \toprule
      & \multicolumn{3}{c}{w = 8} &  \multicolumn{3}{c}{w = 16}  & \multicolumn{3}{c}{w = 32}\\
      \cmidrule(lr){2-4} \cmidrule(lr){5-7} \cmidrule(lr){8-10}
      & t=0 & t=1 & t=2 & t=0 & t=1 & t=2 & t=0 & t=1 & t=2\\\midrule
      dir=1\\
      c & 0.0790 & 0.1692 & 0.2945 & 0.3670 & 0.7187 & 3.1815 & -1.0032 & -1.7104 & -21.7969\\
      c & -0.8651& 50.0476& 5.9384& -9.0714& 297.0923& 46.2143& 4.3590& 34.5809& 76.9167\\
      c & 124.2756& -50.9612& -14.2721& 128.2265& -630.5455& -381.0930& -121.0518& -137.1210& -220.2500\\
      dir=0\\
      c & 0.0357& 1.2473& 0.2119& 0.3593& -0.2755& 2.1764& -1.2998& -3.8202& -1.2784\\
      c & -17.9048& -37.1111& 8.8591& -30.7381& -9.5952& -3.0000& -11.1631& -5.7108& -15.6728\\
      c & 105.5518& 232.1160& -94.7351& 100.2497& 141.2778& -259.7326& 52.5745& 10.1098& -140.2130\\
      \bottomrule
    \end{tabular}
    \caption{Caption}
  \end{sidewaystable}
\end{document}

扭转局势

相关内容