Overfull / Underfull \hbox

Overfull \hbox warns that a line could not be broken to fit and overran the right margin; Underfull \hbox is the opposite — a line that is too loose (spaces stretched too far). The usual culprit is something unbreakable — a long URL, a long word, a code string. This page covers why, and the fixes.

The two warnings

Overfull \hbox (X pt too wide) means characters spilled past the right margin (in draft mode you see a black rule there) — a real visual problem. Underfull \hbox (badness N) means TeX could not break well and stretched the spaces too far — a looseness warning, less urgent. Both report the line range as “in paragraph at lines A--B.”

Common causes

  • A long unbreakable word, a long URL, a code string, or a part number.
  • A narrow column (two-column layouts, inside tables).
  • A short last line forced by \\.

Fixes

  • Reword — the cleanest fix; often one word does it.
  • For a URL, use \url{...} (url / hyperref) so it breaks at sensible points.
  • Load microtype — its subtle character protrusion and font expansion cut overfull/underfull dramatically. A nearly free improvement, worth adding by default.
  • For a stubborn word, allow breaks with \- (discretionary hyphen) or a \hyphenation exception; check the right language is active (babel) — see “Line and page breaks.”
  • Loosen spacing locally with \sloppy / sloppypar.
  • For trivial cases, raise the threshold with \hbadness / \hfuzz to silence the warning without changing output.
latex
\usepackage{microtype}   % overfull/underfull を大幅に減らす / cuts them dramatically
\usepackage{hyperref}    % \url{} を提供 / provides \url
...
\url{https://example.com/very/long/path}   % 適切な位置で折る / breaks sensibly