3

I want to make the right tabular positioning from 50% of the textwidth, so I put 2 slightly smaller tabulars side by side and fill with a hskip and a hfill to avoid overfulling.

\documentclass[a4paper,10pt]{article}

\usepackage{tabularx}

\begin{document}

\section{Tables}

    \begin{tabular*}{.49\textwidth}{ll}
        a & b \\ [.375em]
        c & d
    \end{tabular*} \hskip .01\textwidth
    \begin{tabular*}{.49\textwidth}{ll}
        e & f \\ [.375em]
        g & h
    \end{tabular*} \hfill

\end{document}

However, this ends up with underfulling (under xelatex).

Underfull \hbox (badness 10000) in alignment at lines 9--12
Underfull \hbox (badness 10000) in alignment at lines 13--16
Underfull \hbox (badness 10000) in paragraph at lines 9--17

How to put these two tabulars side by side without a warning?

4
  • 1
    Welcome! It probably doesn't like the lack of stuff in the tabulars. Two characters for almost half the page width isn't much. You've not given a proper example, but unless you have a very small text width, that's going to look awful. Why not use a regular tabular and just use \centering or \hfills or whatever?
    – cfr
    Aug 7, 2017 at 3:46
  • @cfr I edited my question and added a MWE.
    – Kevin Dong
    Aug 7, 2017 at 3:50
  • Simply leave out the hfill at the end? (I'd leave out also the \hskip in the middle or substitute it with an \hfill).
    – CarLaTeX
    Aug 7, 2017 at 3:56
  • Off-topic: you don't need to load tabularx to use tabular*.
    – CarLaTeX
    Aug 7, 2017 at 4:01

3 Answers 3

1

First, having \section makes you disregard the indent.

If you want the left table to start at the left margin and the right table at mid line, you can use two appropriately sized boxes.

\documentclass[a4paper,10pt]{article}

\begin{document}

\noindent
\makebox[.5\textwidth][l]{%
  \begin{tabular}{@{}ll@{}}
  a & b \\ [.375em]
  c & d
  \end{tabular}% <--- don't forget %
}% <--- don't forget %
\makebox[.5\textwidth][l]{%
  \begin{tabular}{@{}ll@{}}
  e & f \\ [.375em]
  g & h
  \end{tabular}% <--- don't forget %
}

% this is to show the center of the text width
\noindent
\rule{.5\textwidth}{0.4pt}%
\makebox[0pt]{\rule{0.4pt}{.5cm}}%
\rule{.5\textwidth}{0.4pt}

\end{document}

enter image description here

The Underfull \hbox messages were mainly due to tabular* not being given flexible intercolumn glue.

The \hfill at the end is removed, because it is followed by \par, so it is irrelevant. Hence the line ends up consisting of

  1. a tabular 0.49 of the text width;
  2. a standard interword space (the space between \end{tabular*} and \hskip;
  3. glue for 0.01 of the text width;
  4. a tabular 0.49 of the text width;
  5. a standard interword space (the space between \end{tabular*} and \hfill).

Beware of unwanted spaces.

The line is actually overfull, so the second line of the paragraph turns out to be underfull, because it has nothing in it. You probaby didn't notice

Overfull \hbox (13.77411pt too wide) in paragraph at lines 9--17
7
  • I am curious about why the original code doesn't end up with overfull rather than underfull? Does that means those interword spaces is shorter than 0.01 of the text width?
    – Kevin Dong
    Aug 7, 2017 at 9:07
  • @KevinDong You got an overfull and an underfull box.
    – egreg
    Aug 7, 2017 at 9:17
  • There are exactly three underfull warnings when compiling with the latest XeTeX. Thanks for you detailed answer.
    – Kevin Dong
    Aug 7, 2017 at 9:23
  • I don't get an overfull box warning with pdfLaTeX with the OP's MWE. Maybe the MWE changed and you were working with an earlier version? @KevinDong Did you originally post an example without the section preceding the first tabular?
    – cfr
    Aug 7, 2017 at 12:42
  • @KevinDong I see that you did. Even though egreg answered after you'd edited the code in the question again, I'm assuming that the answer is based on the earlier MWE you posted, which didn't have a section heading. Without the section heading, you get the additional warning mentioned. With the section heading, you don't, because then there's no indentation here.
    – cfr
    Aug 7, 2017 at 12:45
0

There are a number of other better options to avoid such warnings like tabularx or using normal tabulars inside minipages as you did, etc. But, to know the source of these Underfull warnings you need to look more carefully at your code.

For the last Underfull warning, remove that final \hfill, \hfill should be used between text and not at the end. For the other two warnings, you have too short text in the tables, shorter than .49\textwidth. To avoid this, add @{\extracolsep{\fill}} to tabular headers. Finally, instead of \hskip .01\textwidth between the two tabulars, use \hfill, it will ensure filling up the whole line width automatically.

\documentclass[a4paper,10pt]{article}
\begin{document}

\section{Tables}

    \begin{tabular*}{.49\textwidth}{l@{\extracolsep{\fill}}l}
        a & b \\ [.375em]
        c & d 
    \end{tabular*} \hfill %\hskip .01\textwidth    
    \begin{tabular*}{.49\textwidth}{l@{\extracolsep{\fill}}l}
        e & f \\ [.375em]
        g & h
    \end{tabular*} 

\end{document}

enter image description here

1
  • This does not meet the requirement that the second tabular should start from 50% of the textwidth.
    – Kevin Dong
    Aug 7, 2017 at 6:16
0

This issue can be solved by using two minipages.

\documentclass[a4paper,10pt]{article}

\usepackage{tabularx}

\begin{document}

\section{Tables}

    \begin{tabularx}{.5\textwidth}{ll@{\extracolsep{\fill}}l} % normal
        a & b \\ [.375em]
        c & d
    \end{tabularx}% <-- this is important to avoid overfull
    \begin{tabularx}{.5\textwidth}{@{}ll@{\extracolsep{\fill}}l} % no column separation
        e & f \\ [.375em]
        g & h
    \end{tabularx}

\end{document}
9
  • this still has parindent to the left of the first minipage and a word space before the hskip so the second minipage does not start at .5\textwidth from the left. Aug 7, 2017 at 7:13
  • @DavidCarlisle Doesn't LaTeX by default not indent the first paragraph following a section heading?
    – cfr
    Aug 7, 2017 at 12:34
  • @cfr well yes, I hadn't spotted the section had been added to the answer (and it's not mentioned in the text of the answer but is possibly the main part of the solution as it accounts for ~15pt difference in the line, so I'll leave my comment even if not completely accurate) Aug 7, 2017 at 12:38
  • @DavidCarlisle It isn't added in the answer. It is copied from the question.
    – cfr
    Aug 7, 2017 at 12:46
  • @cfr check the question edit history:-) Aug 7, 2017 at 12:46

You must log in to answer this question.

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