1

I have referred to some questions posted earlier about this same topic, namely this and this for fitting a table into a page. The code is taken from a guide I found online.

\documentclass{article}

\usepackage{booktabs} \newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}

\begin{document}

\begin{table}\centering \ra{1.4} \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}

enter image description here (ignore the red circle)

I tried applying the solutions proposed in the above links to the current example:

  • p{width} as in \begin{tabular}{@{}rrrrcrrrcrrr@{}p{0.8\textwidth}}
  • tabularx environment as in \begin{tabularx}{@{}rrrrcrrrcrrrX@{}}
  • tabular* environment as in \begin{tabular*}{0.8\textwidth}{@{}rrrrcrrrcrrrX@{}}

Edit I am using a simple article class with no packages other than booktabs.

But they did not work? Any thoughts ?

  • Please make your code compile compilable by adding the documentclass as well as the relevant packages. How to make a table fit into the available space depending depends on how much space there is. If you use the geometry package, please include the corresponding setting into your MWE as well. – leandriis Mar 10 '21 at 06:08
  • 1
    I'd start by getting rid of the empty columns between the t=2 and t=0 columns in order to save quite some space. – leandriis Mar 10 '21 at 06:08
  • Additionally, you could use \multicolumn{5} {@{}l}{dir=1} in the first column to save even more space. – leandriis Mar 10 '21 at 06:10
  • @leandriis I suppose so but the guide that I found purposefully introduces these spaces to emphasize on the division between the groupings on the topmost row. – First User Mar 10 '21 at 06:11
  • 1
    If your table still does not fit, you could try a smaller font size and additionally reduce the value of tabcolsep. Alternatively, and especially if your table still does not fit, you could rotate it to a landscape orientation. – leandriis Mar 10 '21 at 06:11
  • 1
    I definitely get that you want to group the columns in groups of 3, but for this, you don't really need an empty column, especially not, if your table is that wide. Instead, try with \midrule(lr){...} instead of \midrule{} and your groups of columns will still be visible. – leandriis Mar 10 '21 at 06:15
  • How wide is the textblock? Any chance you could it increase it from its default? Alternatively, is rendering the table in landscape mode an option you can contemplate? – Mico Mar 10 '21 at 06:26
  • @Mico Unfortunately I am not familiar with either textblock or rendering tables in landscape mode. – First User Mar 10 '21 at 06:36
  • 1
    @FirstUser - The text block of a printed page is surrounded by the margins. The width of the text block is the width of the physical page minus the widths of the left-hand-side and right-hand-side margins. – Mico Mar 10 '21 at 06:49

1 Answers1

2

Unless you're willing and able to either enlarge the width of the textblock or choose a very small font size, I think your best option is to typeset the table in landscape mode, on a page by itself.

The following code achieves that by employing a sidewaystable environment. I would also like to suggest that you (a) employ an array environment intead of a tabular environment (since most of the material is math-y) and (b) load the siunitx package and employ its S column type to align the numbers in the numerical columns on their decimal markers. I would also omit the all-blank columns.

enter image description here

\documentclass{article}

\usepackage{booktabs} % \toprule, \midrule, \cmidrule, \bottomrule, \addlinespace \usepackage{rotating} % for 'sidewaystable' environment \usepackage{siunitx} % for 'S' column type \newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}

\begin{document}

\begin{sidewaystable} \ra{1.1} % 1.4 seems excessive \centering $\begin{array}{@{} l *{9}{S[table-format=-3.4]} @{}} \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 \mbox{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 \mbox{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{sidewaystable}

\end{document}

Mico
  • 506,678