29

I keep getting this warning

 Overfull \hbox (0.63303pt too wide) in paragraph at lines xxx--xxx`

wherever I have this line in the code

 \begin{tabular}{p{2cm}|p{4cm}|p{3cm}|p{3cm}}

It does not stop me from working on and creating documents but I was just wondering why I keep getting that.

4
  • 2
    I wouldn't worry about it to be honest.The difference is probably too small to see at 0.6330pt wide. What class are you using? Most classes will use an \hfuzz figure of at least 1pt to avoid such messages.
    – yannisl
    Commented Nov 30, 2010 at 15:17
  • 1
  • @Yiannis: Right, one doesn't have to worry, but if you have lots of these messages, then the more severe ones might get lost. So I consider it a good idea to try and avoid such minor messages. Commented Nov 30, 2010 at 16:33
  • Could you please add a minimal example that illustrates your problem (including the preamble). Commented Dec 2, 2011 at 22:01

4 Answers 4

25

I assume you get this warning because your tabular is (a little bit) wider than your \textwidth. Solutions include:

  • enlarging the \textwidth a little
  • narrowing down the tabular by a little
  • adding \hfuzz=0.64pt somewhere in the preamble

The \hfuzz setting specifies the maximum amount of box-overflow before a warning message will be issued.

11

use this tabular definition:

\begin{tabular}{@{} p{2cm}|p{4cm}|p{3cm}|p{3cm} @{}}

the definition of a row is

|\tabcolsep|2cm|\tabcolsep|\tabcolsep|4cm|\tabcolsep|...|\tabcolsep|

The @{} remove the \tabcolsep at the beginning and end of the tabular row.

3
  • 1
    Herbert, can you explain what this does?
    – Ingo
    Commented Oct 28, 2013 at 9:42
  • 1
    see my edited answer
    – user2478
    Commented Oct 28, 2013 at 9:58
  • 2
    This answer is fantastic. This explains why width warnings start to show up before the hbox visually overflows. Been through a few forums looking for a reason why the warnings come up too early, and this explains the underlying cause perfectly.
    – Hazok
    Commented Jul 29, 2017 at 3:14
7

Using the new adjustbox package of Martin Scharrer, you can place your tabular inside of an adjustbox. This package will shrink your tabular to fit to the \textwidth (and to the \textheight, if that should be necessary) without distortion of the text (or any other content in the box; keepaspectratio is the key).

\begin{adjustbox}{width={\textwidth},totalheight={\textheight},keepaspectratio}%
\begin{tabular}{p{2cm}|p{4cm}|p{3cm}|p{3cm}}
    ...
\end{tabular}%
\end{adjustbox}

But because it resizes the tabular, it is better suited for cases like

 \begin{tabular}{c|c|c|c}

For columns with fixed width Herbert's solution is more appropriate, which removes horizontal space at the beginning and end of a row.

2
  • While that will work, it will mask the underlying problem (cf. Herbert's answer). Commented Dec 2, 2011 at 22:05
  • @MartinSchröder: Yes, you are right. Thanks for pointing this out. I edited my answer accordingly.
    – Stephen
    Commented Dec 3, 2011 at 19:04
5

One thing that might be useful is using the \resizebox command to scale your environment to the available width of the page. It saves having to manually fiddle with the sizes to make it perfect but can result in text distortion when used on an environment that is far too small/large.

In the case of your tabular environment you would uses it as such:

\resizebox{\textwidth}{!} {%
\begin{tabular}{p{2cm}|p{4cm}|p{3cm}|p{3cm}}
%Fill table with data
\end{tabular}%
}

This will scale the tabular environment to the exact width of the page, with (in this case) negligible text distortion.

5
  • I've added two % characters that avoid spurious spaces.
    – egreg
    Commented May 17, 2011 at 9:29
  • Ah, thanks. I've only used the command for a report where whitespace was desirable so I didn't consider that.
    – Ephphatha
    Commented May 17, 2011 at 9:39
  • To prevent text distortion, I would advise the use of the (new) adjustbox package instead of \resizebox (please see my answer).
    – Stephen
    Commented Nov 24, 2011 at 18:26
  • While that will work, it will mask the underlying problem (cf. Herbert's answer). Commented Dec 2, 2011 at 22:05
  • Maybe I don't understand tex very well, but this is my favorite answer and also the one provided on wikibooks.org en.wikibooks.org/wiki/LaTeX/Tables#Controlling_table_size Commented Feb 24, 2015 at 10:40

You must log in to answer this question.