2

I found a lot of related questions about Overfull \hbox warning and tabularx but none of them have helped me so far.

This is a minimal code which reproduces the warning (the real table isn't so ugly of course):

\documentclass[a4paper,11pt]{article}

\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{siunitx}

\setlength{\extrarowheight}{3pt}


\begin{document}

\begin{tabularx}{0.95\textwidth}{X S[table-format=2.0]}
\toprule
Text & 5 \\ \midrule
A & 51\% \\
B & 39\% \\
C & 30\% \\
D & 25\% \\
E & 20\% \\
F & 17\% \\
G & 8\% \\
H & 6\% \\
I & 3\% \\
\bottomrule
\end{tabularx}

\end{document}

and this is the output

This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./main.tex
LaTeX2e <2014/05/01>
Babel <3.9l> and hyphenation patterns for 79 languages loaded.
(/usr/local/texlive/2014/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/local/texlive/2014/texmf-dist/tex/latex/base/size11.clo))
(/usr/local/texlive/2014/texmf-dist/tex/latex/booktabs/booktabs.sty)
(/usr/local/texlive/2014/texmf-dist/tex/latex/tools/tabularx.sty
(/usr/local/texlive/2014/texmf-dist/tex/latex/tools/array.sty))
(/usr/local/texlive/2014/texmf-dist/tex/latex/siunitx/siunitx.sty
(/usr/local/texlive/2014/texmf-dist/tex/latex/l3kernel/expl3.sty
(/usr/local/texlive/2014/texmf-dist/tex/latex/l3kernel/expl3-code.tex
(/usr/local/texlive/2014/texmf-dist/tex/latex/etex-pkg/etex.sty))
(/usr/local/texlive/2014/texmf-dist/tex/latex/l3kernel/l3unicode-data.def)
(/usr/local/texlive/2014/texmf-dist/tex/latex/l3kernel/l3pdfmode.def))
(/usr/local/texlive/2014/texmf-dist/tex/latex/l3packages/xparse/xparse.sty)
(/usr/local/texlive/2014/texmf-dist/tex/latex/amsmath/amstext.sty
(/usr/local/texlive/2014/texmf-dist/tex/latex/amsmath/amsgen.sty))
(/usr/local/texlive/2014/texmf-dist/tex/latex/l3packages/l3keys2e/l3keys2e.sty)
(/usr/local/texlive/2014/texmf-dist/tex/latex/beamer/translator/translator.sty
(/usr/local/texlive/2014/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/local/texlive/2014/texmf-dist/tex/latex/beamer/translator/translator-lang
uage-mappings.tex))) (./main.aux)
(/usr/local/texlive/2014/texmf-dist/tex/latex/beamer/translator/dicts/translato
r-basic-dictionary/translator-basic-dictionary-English.dict)
(/usr/local/texlive/2014/texmf-dist/tex/latex/siunitx/siunitx-abbreviations.cfg
)
Overfull \hbox (9.12502pt too wide) detected at line 25
\OT1/cmr/m/n/10.95 % 

Overfull \hbox (9.12502pt too wide) detected at line 25
\OT1/cmr/m/n/10.95 % 

Overfull \hbox (9.12502pt too wide) detected at line 25
\OT1/cmr/m/n/10.95 % 

Overfull \hbox (9.12502pt too wide) detected at line 25
\OT1/cmr/m/n/10.95 % 

Overfull \hbox (9.12502pt too wide) detected at line 25
\OT1/cmr/m/n/10.95 % 

Overfull \hbox (9.12502pt too wide) detected at line 25
\OT1/cmr/m/n/10.95 % 

Overfull \hbox (9.12502pt too wide) detected at line 25
\OT1/cmr/m/n/10.95 % 

Overfull \hbox (9.12502pt too wide) detected at line 25
\OT1/cmr/m/n/10.95 % 

Overfull \hbox (9.12502pt too wide) detected at line 25
\OT1/cmr/m/n/10.95 % 
[1{/usr/local/texlive/2014/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
(./main.aux) )
(see the transcript file for additional information)</usr/local/texlive/2014/te
xmf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb>
Output written on main.pdf (1 page, 15096 bytes).
SyncTeX written on main.synctex.gz.
Transcript written on main.log.

The line 25 is \end{tabularx}.


What I tried:

  • use \noindent before opening tabularx environment;
  • reduce the width of the table;
  • use \end{tabularx}{\parfillskip=0pt\par}
  • change the column in {@{}X@{}S[table-format=2.0]@{}}.

Any help would be appreciated.

2 Answers 2

1

You need to add some room for the % (S[table-format=2.0] only makes the column wide enough for the numbers to which the % is tacked on, resulting in an overfull box). Try:

\documentclass[a4paper,11pt]{article}

\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{siunitx}

\setlength{\extrarowheight}{3pt}


\begin{document}

\begin{tabularx}{0.95\textwidth}{X S[table-format=2.0,table-space-text-post={\%}]}
\toprule
Text & 5 \\ \midrule
A & 51\% \\
B & 39\% \\
C & 30\% \\
D & 25\% \\
E & 20\% \\
F & 17\% \\
G & 8\% \\
H & 6\% \\
I & 3\% \\
\bottomrule
\end{tabularx}

\end{document}
2
  • 1
    Using \noindent before the tabularx is better than guessing a width, that can be \textwidth, then. Instead of repeating \% in each cell, it's much better to put it once and for all in the header in parentheses.
    – egreg
    Oct 17, 2015 at 22:45
  • I would write \,\% rather than merely \%.
    – Bernard
    Oct 17, 2015 at 22:56
1

Another solution, automating the typesetting of %:

\documentclass[a4paper,11pt]{article}

\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{siunitx}

\setlength{\extrarowheight}{3pt}

\begin{document}

 \begin{tabularx}{0.95\textwidth}{X S[table-format=2.0]<{\,\%}}
  \toprule
  Text & \multicolumn{1}{c}{5} \\ \midrule
  A & 51 \\
  B & 39 \\
  C & 30 \\
  D & 25 \\
  E & 20 \\
  F & 17 \\
  G & 8 \\
  H & 6 \\
  I & 3 \\
  \bottomrule
\end{tabularx}

\end{document} 

enter image description here

You must log in to answer this question.