Often, TeX outputs underfull hbox warnings when running and in the generated log file. What are these and how can I get rid of them?
4 Answers
TeX puts elements (letters, lines, paragraphs, pictures,...) in boxes and joins them together on pages using glue (put between them) that can stretch, e.g., to make sure that lines are justified, or that pages are filled to their specified height. In the first example, the line is put in a hbox (horizontal box, or box with material arranged horizontally with respect to one another, words in this case), in the second, the page is put in a vbox (vertical box, or box with material arranged vertically with respect to one another, usually paragraphs and displayed equations in this case).
Such a box is underfull in case TeX has to stretch the glue more than what is specified to be (aestethically) acceptable. In that case there will, e.g., be much whitespace between words of a line (hbox case) or extra whitespace between paragraphs (vbox case).
To avoid underfull hboxes (and also overfull ones), one can, in LaTeX, use the microtype package, which, when used in pdflatex mode (directly generating a .pdf
file, and not a .dvi
one), can stretch letters as well, which allows TeX to get acceptable whitespace in lines more often.
Another, manual route is to reformulate sentences and paragraphs, or add explicit hyphenation (e.g., hyphen\-ation
) to get better linebreaks. One can sometimes even fix bad pagebreaks (overfull vboxes) in this way as well, by shortening or lengthening paragraphs with one line.
-
14BTW, you can also explicit hyphenation by adding
\hyphenation{con-sti-tu-tion-al}
to the preamble, as long as you use thefontenc
package (with optionT1
, I believe). This is useful if you don't want to bother trying to guess where LaTeX should break the word in order to adjust the line width. Commented Aug 1, 2014 at 21:06 -
3@WaldirLeoncio The point here is to do hyphenation explicitly to fix a local problem, so your comment is off-topic, albeit correct.– equaegheCommented Aug 2, 2014 at 21:30
An underfull hbox means LaTeX couldn't space the line wide enough to fill the entire width of the page, without increasing word spacing beyond the allowed maximum; the opposite is an overfull hbox, where a line couldn't be broken and extends past the edge of the printable area. Usually it happens if you forced a linebreak yourself (with \\
), so if you avoid doing that this should be pretty rare (other causes are weird tabular environments or forced blank lines)
-
7I would add that the overfull/underfull vboxes occur when TeX cannot break the page at the right place. This almost never happens if you have enough text on the page, but with lots of tabulars or equation arrays they can appear.– finrodCommented Jul 26, 2010 at 20:49
-
-
In addition to @finrod 's helpful examples... I was getting this warning when i was using wrapfig and my figures were resulting in pages with relatively slim columns of text.– user84793Commented May 5, 2018 at 13:24
Often, TeX outputs underfull hbox and vbox warnings when running and in the generated log file. What are these and how can I get rid of them?
That's just TeX alerting you that it was unable to typeset your document perfectly. Since a large document might trigger lots of these warnings, it's useful to be able to suppress them. I found the following trick on https://tex.stackexchange.com/a/19212/126270 —
\hbadness=99999 % or any number >=10000
The \hbadness
variable doesn't affect the typography at all; it just tells TeX the threshold for printing its annoying "Underfull \hbox (badness xxxx) in paragraph..." warnings. The higher you set \hbadness
, the fewer such warnings you'll see. I confirm that this trick worked for me.
This trick does not suppress "Overfull \hbox (xxxx too wide) detected at line..." warnings. To suppress those, allegedly you can use
\hfuzz=99999pt
although that trick has not worked for me in practice. https://tex.stackexchange.com/a/50850/126270 is a very good summary of all TeX's box-related warning (suppression) mechanisms.
-
3That is answer. It is important to know why and try other things if you can. But when you passed that threshold, you just want to get rid of the ones that has no solution or are unimportant. +1 and I would +2 if I could.– DrBecoCommented Sep 28, 2018 at 16:14
-
2
\hbadness=99999
worked great for me, but\hfuzz=99999pt
gives meDimension too large
error and when I tried\hfuzz=9999pt
I still had the\hbox (xx.xxxxxxpt too wide)
Bad Box
- alerts Commented Apr 23, 2020 at 19:37 -
@Cold_Class tex.stackexchange.com/a/392856/107497 suggests that other packages may be interfering, but that you can follow your command with
\newdimen\hfuzz
to prevent that. That seemed to work for me.– TeepeemmCommented Jun 18, 2020 at 19:51
Typically \\
will cause this because you have a blank line with no content (where the TeX algorithm expects content). You could get rid of those and space correctly (if you want extra space between paragraphs, use, e.g., \setlength{\parskip}{6pt}
). It also can occur when you have a really long object in a paragraph that is not enough to fill it completely (hence "underfull"). Lastly, in some cases, if you have really long words, the TeX algorithm has a difficult time finding a proper way to justify the paragraph without having underfull boxes (the text doesn't meet the very end of the line). You can avoid this by using some shorter words or rewriting some stuff to accommodate the algorithm.
-
6Using
\setlength{\parskip}{...}
is great if you want extra space between every paragraph. If you want some extra space to appear in one spot but not all the time, you can also use\vspace{...}
.– DGradyCommented Feb 9, 2013 at 0:03 -
2In addition to what @DGrady said, you can use
\bigskip
or\medskip
which are basically\vspace{predefined_val}
– ShailenCommented Aug 21, 2014 at 15:17 -
What if I write \\ , put a blank line and then write something?. In this scenario, there is something written after \\, but I am still getting this error! Commented Mar 31, 2020 at 4:04