# Overfull \hbox warning when using tabular

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.

-
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. – Yiannis Lazarides Nov 30 '10 at 15:17
– Charles Stewart Nov 30 '10 at 16:07
@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. – Hendrik Vogt Nov 30 '10 at 16:33
Could you please add a minimal example that illustrates your problem (including the preamble). – Martin Schröder Dec 2 '11 at 22:01

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.

-

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}%


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.

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

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.

-
Herbert, can you explain what this does? – Ingo Oct 28 '13 at 9:42
see my edited answer – Herbert Oct 28 '13 at 9:58
Thank you for the additions. – Ingo Oct 28 '13 at 11:47

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.

-
I've added two % characters that avoid spurious spaces. – egreg May 17 '11 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 May 17 '11 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 Nov 24 '11 at 18:26
While that will work, it will mask the underlying problem (cf. Herbert's answer). – Martin Schröder Dec 2 '11 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 – tommy.carstensen Feb 24 '15 at 10:40