Overfull / Underfull \hbox

Overfull \hbox is a warning, not an error. The LaTeX run finishes, the PDF exists — one line of it simply sticks out past the right margin. So the first thing to do is not to stare at the log but to open the PDF and look at that line. From there this page works through what the number in (71.93637pt too wide) measures, how in paragraph at lines 4--9 differs from detected at line 3, which of \hbadness, \tolerance and \emergencystretch you should actually touch, and why fixing an overfull box and silencing the warning are two completely different operations. Its mirror image, Underfull \hbox, and the vertical Overfull \vbox belong to this page too.

What the number in (71.93637pt too wide) measures

By how much that line exceeded \hsize, the column width, measured in points. One point is about 0.35 mm, so half a point is invisible to the naked eye while seventy points is a thumb’s width hanging off the page. That single number sets your priority — a few points and nobody will notice, which is why LaTeX stays silent below 0.1 pt by default (\hfuzz=0.1pt). TeX typesets in boxes, and the box holding one line of characters side by side is a horizontal box: an \hbox. Overfull \hbox means that when the paragraph was broken into lines, the contents of one box came out wider than the column and could not be squeezed any further. The reason a line cannot be squeezed is almost always the same: there was nowhere in it to break.

The second half of the warning — something like in paragraph at lines 4--9 — tells you where it happened. There are four such phrasings, and which one you got changes where to look, so use the table below to identify yours. Each was reproduced here with a minimal file under pdfLaTeX from TeX Live 2024. The awkward one is has occurred while \output is active, which means “while the page was being assembled”: the offending material may not correspond to any line you wrote. There is a trap in the other direction too — a plain \mbox{...} or \makebox[2cm]{...} issues no warning at all, however far its contents stick out. The \hss they pad with can shrink without limit, so as far as TeX is concerned the box always fits exactly, and characters walk over the margin without leaving a trace in the log.

PhrasingWhat it meansWhere to look
in paragraph at lines A--Bit happened while breaking an ordinary paragraphthe paragraph spanning lines A to B — by far the most common
detected at line Nit happened in an explicit fixed-width box, not a paragraphan \hbox to, a \makebox[…][s], a box built by a package — on line N
in alignment at lines A--Bit happened inside a table alignmenta width-constrained table such as tabular* or tabularx
while \output is activeit happened while the page was being assembledheaders, footers, footnotes, floats — the line number is unreliable

The log shows you the guilty line, hyphenation points and all

Directly under the warning, TeX prints the contents of the offending line — with a - inserted at every hyphenation point it found. That is the heart of the diagnosis. Below is a real log from pouring English text into a 4 cm column. Note that Wis-senschaft-skol-leg carries hyphens while electroencephalography- carries none: TeX excludes a word containing an explicit hyphen from automatic hyphenation (its scan stops at the explicit hyphen). So that line genuinely has nowhere to break, and no amount of raising \tolerance will help. Reading the hyphens in the log tells you at a glance whether hyphenation is being attempted at all or has been given up on — and a line with no hyphens anywhere is a strong hint that the language setting is wrong.

log
Overfull \hbox (13.35585pt too wide) in paragraph at lines 4--9
\OT1/cmr/m/n/10 The Wis-senschaft-skol-leg pub-
 []

Overfull \hbox (80.27266pt too wide) in paragraph at lines 4--9
\OT1/cmr/m/n/10 li-ca-tion de-scribes an electroencephalography-
 []

To see the offending spot on the page, add the draft class option. article.cls contains \DeclareOption{draft}{\setlength\overfullrule{5pt}}, which puts a 5 pt black rule in the margin beside every overfull line. The reason you do not normally see those bars is that latex.ltx finishes by executing \overfullrule 0pt, cancelling INITEX’s default of 5 pt. The black bars are merely switched off, and can be switched back on at any time: if you would rather not touch the class options, \overfullrule=5pt in the preamble does the same thing — just remember to remove it before submission.

Why narrow columns, tables and code produce most overfull boxes

Because the narrower the column, the more fatal the relative length of an unbreakable word becomes. In a 10 cm column a 3 cm word takes up a third of the line; in a 4 cm column it is longer than the line, and no choice of break can keep it inside. When the same manuscript jumps from a handful of warnings to dozens the moment you switch to two columns, it is not that the prose got worse — the measure got halved. The places below are where overfull boxes cluster; if one of them rings a bell, start there. Recognising the column as the cause changes the remedy: reviewing the width of one p{} column is often quicker than scattering \sloppy over paragraphs.

  • Two-column layouts (\documentclass[twocolumn], multicol). The measure roughly halves, so words that were fine in one column all overflow at once.
  • p{}, m{} and b{} table columns, and tabularx. Column widths are numbers the author chose, and they are frequently too narrow for what goes in them.
  • Verbatim environments (verbatim, \verb, listings). Spaces and line ends are reproduced exactly, so TeX has no freedom to break at all.
  • URLs, DOIs, file paths, part numbers, chemical names, gene names. A long string with no spaces in it counts as a single word.
  • Inline mathematics. By default a formula may only break after a binary operator or a relation, and not at all inside constructs such as \frac.
  • Footnotes and float captions. They are sometimes set at a narrower measure than the body, and tend to be reported in the \output is active form.

Getting rid of an overfull hbox, best fix first

Rewording one phrase is the best fix. It is an unglamorous answer, but it is the only solution that no software can supply for you, and it usually takes five seconds: swap a long word for a shorter synonym, reorder a clause, move a long part number into a footnote, and the box fits. There is a reason this ranks first. TeX breaks lines by considering the paragraph as a whole, an algorithm published by Knuth and Michael Plass in their 1981 paper Breaking Paragraphs into Lines, so changing the last word of a paragraph can change how the first line breaks. Turned around: one word moved by the author widens the typesetter’s room for manoeuvre enormously. The remedies below are ordered by effect against side effect.

  • Reword. Usually one word does it, with no side effects at all. Long part numbers and product names belong in a footnote or a table.
  • Check the language. German or French body text with English hyphenation patterns applied finds nowhere to break. With babel, \usepackage[ngerman]{babel}; under XeLaTeX or LuaLaTeX, polyglossia’s \setmainlanguage{german}.
  • Let that one word break. \- inside a word marks a discretionary hyphen; \hyphenation{Wis-sen-schafts-kol-leg} registers an exception in the preamble. For a compound that already contains an explicit hyphen, inserting \hspace{0pt} after the hyphen restores a break opportunity.
  • \sloppy, or the sloppypar environment. Loosens inter-word spacing for the paragraph. sloppypar is the safer of the two because it closes again at \end.
  • Raise \emergencystretch. Measured here, \emergencystretch=3em alone turned five overfull boxes into zero — at the cost of seven underfull ones. The side effect is loose word spacing, which is far less visible than text hanging off the page.
  • Load microtype. Its subtle character protrusion and font expansion cut the overhang from 13.4 pt to 8.9 pt and from 80.3 pt to 74.9 pt in the same test. Note that it reduces; it does not remove.
  • As a last resort, \linebreak or \mbox. Breaking by hand. Any later edit to the sentence moves the break, so keep this for the final pass before submission.

What \tolerance, \emergencystretch, \hbadness and \hfuzz each do

The first two change the typesetting; the last two only change what gets reported. Confuse them and you will “fix” a problem you have merely hidden: raise \hfuzz and the overfull reports vanish, but not one character moves on the page. TeX breaks a paragraph in up to three passes — first within \pretolerance and without hyphenation, then within \tolerance with hyphenation, and if that still fails, a third pass with \emergencystretch of extra stretchability added to every line. \emergencystretch acts only in that third pass, which is exactly its character: the last card, played when nothing else worked. LaTeX’s defaults are written into latex.ltx as \tolerance=200, \hbadness=1000 and \hfuzz=0.1pt. The much-used \sloppy lives in the same file and turns out to be only four assignments: \tolerance 9999, \emergencystretch 3em, \hfuzz .5pt, \vfuzz\hfuzz. So \sloppy is not merely “raise the tolerance” — it sets \emergencystretch too, and in the test above \emergencystretch=3em on its own gave results identical to \sloppy.

ParameterLaTeX defaultWhat it does
\tolerance200the worst badness a line may have; raising it changes the typesetting
\emergencystretch0ptextra stretchability added only in the third pass; changes the typesetting
\hbadness1000only lines worse than this are reported as underfull. Output unchanged
\hfuzz0.1ptoverhang up to this much is not reported. Output unchanged
\overfullrule0ptwidth of the black rule drawn beside an overfull line; draft sets it to 5pt
preamble
% changes the typesetting -- use these to actually fix boxes
\emergencystretch=3em     % last-resort stretch on the third pass
\usepackage{microtype}    % protrusion and font expansion

% changes only the log -- the page looks exactly the same
\hbadness=10000           % never report Underfull \hbox
\hfuzz=1pt                % ignore overhangs below 1pt

When a long URL or a code string refuses to break

Wrapping it in \url{} is often not enough. Measured in a 5 cm column, a long URL as bare text overhung by 79.0 pt; putting it in url’s \url{} still left two boxes, 42.4 pt and 10.8 pt. \url{} only breaks after characters such as / and ., so it cannot break inside a host name or a long path segment. Two things do work. Adding \sloppy brought the overfull count to zero, replacing it with underfull — the loose word spacing that always comes with \sloppy is the price. Better still, \usepackage{xurl} produced zero overfull and zero underfull boxes, because xurl permits a break at any position inside a URL. hyperref loads url internally, so its breaking behaviour is the same, and its breaklinks option is what lets a link itself be split. For code listings the equivalent switch is breaklines=true in listings.

preamble
\usepackage{hyperref}   % loads url internally; add breaklinks for split links
\usepackage{xurl}       % allows a break at any point inside a URL
...
\url{https://example.org/proceedings/vol12/paper-0037.pdf}

Underfull \hbox (badness N) is the opposite symptom

A line came out too short and TeX stretched the word spaces to fill it — that is Underfull \hbox. It is the less urgent of the pair, and the badness figure tells you how bad. Badness runs from 0 (perfect) to 10000 (the ceiling: “it cannot get worse”). Intermediate values such as 1590, 2050 and 7667 turn up in practice, but a run of badness 10000 means visibly gappy spacing, so go and look at the PDF. The usual cause is a side effect of chasing overfull boxes: \sloppy or \emergencystretch converts overfull into underfull (five boxes down to zero in the test above, with seven underfull appearing in their place). The other cause is a short line forced mid-paragraph by \linebreak or \\. \linebreak means “break here but still fill the measure”, so the spaces stretch; \newline and \\ mean “end the line here”, so they do not. When you want a deliberately short line, use \\. If you only want the message gone, \hbadness=10000 silences it — and changes nothing on the page.

Overfull \vbox (… too high) and Underfull \vbox

The same story runs vertically, with height in place of width. Overfull \vbox (56.90552pt too high) means the contents did not fit into a vertical box of fixed height. In testing, an explicit box such as \vbox to 1cm{\hrule height 3cm} reports it as detected at line 3. The form you meet in real documents comes from page assembly: putting a figure or a \rule taller than \textheight produced Overfull \vbox (85.35828pt too high) has occurred while \output is active. When you see that, the first suspect is an illustration too big to fit on one page. Underfull \vbox (badness 10000) is the reverse — vertical glue was stretched to fill the height. Under \flushbottom, the default in the book class, the bottom of every page is aligned by stretching vertical space, so sparse pages produce it readily. If you do not care, switch to \raggedbottom, or raise the reporting thresholds with \vbadness and \vfuzz — and again, raising a threshold changes nothing on the page. When a figure genuinely will not fit, \enlargethispage can extend the text area for that page alone.