1

I want to get something like this: enter image description here

I used the following code:

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

But I got: enter image description here

I don't know how did the overfull \hbox problem happen.

  • Make an educated guess! Hint: Look at the width of your table ;-) A table with about 12 columns having numbers as content is too wide in almost any case (unless typeset in landscape mode) – user31729 Sep 6 '15 at 23:27
  • Clearly you must realise the table is too wide ;). The real question is: what do you want to do about it? One option is obviously to put less content in the table. Since you are here, I guess that option doesn't appeal. So what does? Do you want to turn the table on its side? Use a smaller font? Reduce the separation between columns? Rearrange it somehow? – cfr Sep 6 '15 at 23:46
  • There is a whole host of questions devoted to tables that are too wide. It really depends on what you want to do with this table, but there's surely a duplicate in there somewhere. – Werner Sep 6 '15 at 23:53
2

It will fit within the margins loading the geometry package, which makes more sensible margins, setting font size to footnotesize and reducing \arraycolsep. Btw I replaced the tabular environment with array, to have a simpler code.

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

enter image description here

1

Here's another option which turns the table rather than reducing the font size etc. This also allows you to keep the spacing at the left and right of the extreme columns which I think is needed with a booktabs layout with rules.

I've simplified in a couple more ways. I've removed the columns used for spacing and instead use a specific skip, loading the array package. I've also used this to define a new column type, setting everything as maths which makes input easier.

I've used the (lr) option to \cmidrule so that the line here is broken appropriately without the need for the additional columns. Allowing the usual spacing at the right of the table also helps this breaking of the inner rule to look properly balanced.

This fits without reducing the font size or margins, although you may wish to adjust the page layout for smaller margins for other reasons which would then give you greater flexibility here.

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

turning the table

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.