0

I'm having trouble getting two tables to sit nicely next to each other. I get errors like this:
Overfull \hbox (255.00095pt too wide) in paragraph at lines 9--35
It looks like this:


enter image description here


It seems to insist on this big stupid blank spot (much wider than the margin) that takes up the first quarter of the page, and causes the fourth quarter of the content to fall off the edge, despite using \centering, \begin{centered}, etc.

You can see I tried a few different things (commented out).
Here's the code:

\documentclass[varwidth]{article}

\usepackage{booktabs}

\begin{document}

% \begin{table}
% \begin{minipage}[t][29.7cm][c]{21cm}
\begin{tabular}{cc}
\begin{tabular}{cccc}
\toprule
            &   $X$       &   $X$       &   $XXX$     \\
\midrule 
XXXXXX      &   XXXXXXXX    &   XXXXXXXX    &   XXXXXXXX  \\
\midrule
XXXXXXX     &   XXX         &   XXX         &   XXX       \\
\bottomrule
\end{tabular} &
    % \caption{A}\label{tab:first}
%   \end{minipage}%
% \begin{minipage}[t][29.7cm][c]{21cm}
\begin{tabular}{cccc}
\toprule
            &   $X$       &   $X$       &   $XXX$     \\
\midrule 
XXXXXX      &   XXXXXXXX    &   XXXXXXXX    &   XXXXXXXX  \\
\midrule
XXXXXXX     &   XXX         &   XXX         &   XXX       \\
\bottomrule
\end{tabular} 
\end{tabular}
    % \caption{B}\label{tab:second}
%   \end{minipage}
% \end{table}
\end{document}

So, I have two tables side by side and they overflow into the righthand margin. How can I split the difference between both margins (bleed evenly into each) to keep the tables centered? Just to clear up any confusion, here are a couple of mockups to show the kind of thing I'm going for.

enter image description here

15
  • 4
    The two tables are actually too wide to fit side by side with LaTeX's default margins. Add \usepackage[margin=5mm,showframe]{geometry} to your example and it will fit. (You'll also need a \noindent in front of your first tabular environment if you don't put everything in a table environment.) Commented Aug 7, 2019 at 4:14
  • The "big stupid blank spot" is in fact the left margin plus the width of the usual parindent. If you want to make the margins visible, you can use \usepackage{showframe} in your preamble.
    – leandriis
    Commented Aug 7, 2019 at 9:04
  • @leandriis No need for air quotes. It's big. It's stupid. It's blank. Thanks though, that's actually pretty useful. I can't believe the default margins are so big; they take up almost half the entire page. It would be more useful to remain centered; just split the difference and spill into both margins by default.
    – voices
    Commented Aug 7, 2019 at 9:58
  • tex.stackexchange.com/questions/71172/… Commented Aug 7, 2019 at 10:15
  • 1
    @tjt263 that is not really anything to do with margins, a box starts where you place it (at the left of the tex block in this case) and if it is overfull then it will stick out to the right of its allotted space. If you want it to stick into the left margin you can use \hspace*{-1in} either side then it can be 2in bigger than \textwidth without being overfull. Commented Aug 7, 2019 at 18:58

2 Answers 2

1

The margins are just the standard margins for the document class and page size (US Letter) that you have specified. You also have a paragraph indent to the left, and two lots of \tabcolsep spacing from the tabular columns. (The outer tabular is doing nothing other than add this extra space as there is no actual alignment in the outer, one row table.)

If you want the tables side by side you need to make the page wider or the tables smaller, I opted for the latter here, as well as removing the paragraph indent and the superfluous space from the nested tabluar \tabcolsep.

\documentclass
 %?[varwidth]
{article}

\usepackage{booktabs}

\begin{document}

% \begin{table}
% \begin{minipage}[t][29.7cm][c]{21cm}
%\begin{tabular}{cc}
\centering
\tiny
\setlength\tabcolsep{2.9pt}
\begin{tabular}{@{}cccc}
\toprule
            &   $X$       &   $X$       &   $XXX$     \\
\midrule 
XXXXXX      &   XXXXXXXX    &   XXXXXXXX    &   XXXXXXXX  \\
\midrule
XXXXXXX     &   XXX         &   XXX         &   XXX       \\
\bottomrule
\end{tabular}%
\begin{tabular}{cccc@{}}
\toprule
            &   $X$       &   $X$       &   $XXX$     \\
\midrule 
XXXXXX      &   XXXXXXXX    &   XXXXXXXX    &   XXXXXXXX  \\
\midrule
XXXXXXX     &   XXX         &   XXX         &   XXX       \\
\bottomrule
\end{tabular}
    % \caption{B}\label{tab:second}
%   \end{minipage}
% \end{table}

\normalsize
X\dotfill normal text block\dotfill X
\end{document}

enter image description here

4
  • Thanks, but now it's basically just one table; two halves of a whole. Is that the superfluous space you mentioned? It should look more like two individual entities arranged horizontally. Basically, there is an even number of tables and only an odd number will fit on one page and it ruins the flow of information. So I'm presenting them in pairs to utilize the space, so it's a page of tables, rather than a sparse string of tables scattered over several pages. I hope I explained it well. Does it work with captions and labels too? I commented them out just to isolate the problem.
    – voices
    Commented Aug 7, 2019 at 7:35
  • @tjt263 no I meant that your outer tabular was not aligning anything (as only one row) so the only thing it was doing is making you get twice the cell padding (\tabcolsep) on from the outer and one from the inner table. Since your "question" was mostly a complaint about spacing removing the outer table seemed to be the main point of the answer. You can of course use \caption if you put this in a table environment. However \tiny text verges on unreadable unless this is always pdf where people can scroll in, on paper I wouldn't go this small. Commented Aug 7, 2019 at 8:10
  • Wait, so your suggestion is basically just use a smaller font?
    – voices
    Commented Aug 7, 2019 at 10:04
  • Your tables are wider than the page you have specified, so the choices are to make the tables smaller or the page wider. Usually in most publications the page size is a given and fixed for a document,so that only leaves making the tables smaller. If you want some other outcome you should ask for that in the question. This does not just use a smaller font size, it removes a lot of additional space that you had added (\parindent` and multiple \tabcolsep) @tjt263 Commented Aug 7, 2019 at 10:10
1

The two tables need to fit side-by-side, to begin with. If your tables are wider than half the text width, they don't fit side by side.

Here's a proposal with subcaption, but note the very wide size reserved for text.

\documentclass{article}
\usepackage[margin=1cm]{geometry}

\usepackage{booktabs,subcaption}

\begin{document}

\begin{table}
\centering

\renewcommand{\thesubtable}{\Alph{subtable}}
\captionsetup[subtable]{labelformat=simple}

\small

\subcaptionbox{\label{tab:first}}{%
  \begin{tabular}{cccc}
  \toprule
          & $X$      & $X$      & $XXX$    \\
  \midrule 
  XXXXXX  & XXXXXXXX & XXXXXXXX & XXXXXXXX \\
  \midrule
  XXXXXXX & XXX      & XXX      & XXX      \\
  \bottomrule
  \end{tabular}%
}\hfill
\subcaptionbox{\label{tab:second}}{%
  \begin{tabular}{cccc}
  \toprule
          & $X$      & $X$      & $XXX$    \\
  \midrule 
  XXXXXX  & XXXXXXXX & XXXXXXXX & XXXXXXXX \\
  \midrule
  XXXXXXX & XXX      & XXX      & XXX      \\
  \bottomrule
  \end{tabular}%
}

\caption{Global caption}

\end{table}

\end{document}

enter image description here

1
  • You're also saying to make the tables smaller, right? I don't care If the tables encroach the margins. If they do, I want them to remain centered. I added a picture to demonstrate.
    – voices
    Commented Aug 7, 2019 at 18:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .