All posts

Overfull \hbox: what it means and how to fix it

Your document compiled, but the log says "Overfull \hbox (14.2pt too wide)". Here's what LaTeX is telling you, when you can ignore it, and the fix for each of the usual causes: long words, URLs, inline math, code and wide tables.

A line of LaTeX source in the Luzbase editor with a wavy underline under a long URL, and a tooltip reading Overfull \hbox (14.22636pt too wide) in paragraph at lines 41--42.
Overfull \hbox (14.22636pt too wide) in paragraph at lines 41--42
[]\T1/cmr/m/n/10 The dataset is available at \T1/cmtt/m/n/10 https://data.example.org/

It's the most common message in any LaTeX log. The PDF builds, nothing looks broken at first glance, and the log still complains. Most people learn to scroll past it. That's fine for some of these warnings, but not for all of them: some are the reason a line of your paper sticks out into the margin.

Here's how to tell the two apart, and how to fix the ones that matter.

What LaTeX is telling you

LaTeX builds every line of a paragraph as a horizontal box, an hbox, exactly as wide as the text column. To fill each line it stretches or squeezes the spaces between words and hyphenates where it can.

Sometimes it can't find any good place to break. A long URL, a word it doesn't know how to hyphenate, a chunk of inline math: none of these can be split, and squeezing the spaces isn't enough. So LaTeX gives up and lets the line run past the right margin. That line is overfull, and the log tells you three things about it:

  • 14.22636pt too wide: how far it sticks out. A point is about 0.35 mm, so 14pt is roughly 5 mm. Easy to see in print.
  • in paragraph at lines 41--42: where the paragraph is in your source file.
  • The line after it: the start of the text that didn't fit, with font names like \T1/cmr/m/n/10 mixed in. Ignore the font names and read the words.

The message is a warning, not an error. Your compile still succeeds.

Which ones to fix

A rule of thumb:

  • Under 1pt: invisible. Ignore it.
  • 1pt to 3pt: you'll only notice it if the line is next to a perfectly straight margin. Fix it before submitting, if it's easy.
  • Over 3pt: visible. Fix it. Reviewers and copy editors notice text in the margin.

To see which lines are overfull in the PDF, add this to your preamble:

\setlength{\overfullrule}{5pt}

Every overfull line now gets a black bar in the right margin, so you can scan the pages instead of the log. Remove it before you submit. (The draft class option does the same, but it also replaces your figures with empty boxes.)

Finding them in Luzbase

You don't need to search the log for line numbers. When a compile finishes, Luzbase underlines the source line each bad box starts on, with a marker in the gutter. Hover the underline to see the message:

Overfull \hbox (14.22636pt too wide) in paragraph at lines 41--42

The underline uses the same quiet colour as other informational hints, not the red of a real error, because a bad box never stops your PDF from building. If you want the full context, it's under Show full log in the Output panel.

The usual causes, and the fix for each

A word LaTeX can't hyphenate

Technical terms, names and compound words often aren't in LaTeX's hyphenation dictionary. Tell it where it can break:

% Once, in the preamble, for every use of the word:
\hyphenation{hetero-scedas-ticity Schwarz-schild}

% Or just here, inline:
hetero\-scedas\-ticity

LaTeX also never hyphenates a word that already contains a hyphen, except at that hyphen. "State-of-the-art" can only break at its dashes.

A long URL

URLs have no spaces and no hyphenation points, so they're the single most common cause. Load xurl, which lets a URL break after any character:

\usepackage{hyperref}
\usepackage{xurl}

Then write the link with \url{…}. If you type the URL as plain text, LaTeX treats it as one very long word.

Inline math

LaTeX can only break inline math after a relation like = or an operator like +, and only at the top level. A long $…$ expression, or one wrapped in braces, can't break at all. If an inline formula is longer than about half a line, move it to a display:

\begin{equation}
  \mathcal{L}(\theta) = -\sum_{i=1}^{N} y_i \log \hat{y}_i + \lambda \lVert \theta \rVert_2^2
\end{equation}

It's easier to read that way too.

Code and \texttt

Monospaced text isn't hyphenated, and code listings don't wrap unless you ask them to. For listings:

\lstset{breaklines=true}

For minted, use the breaklines option on the environment. For a long function name in running text, \texttt{} won't break it, so either rephrase the sentence so the name lands earlier in the line, or allow a break with \allowbreak inside the name: \texttt{load\_\allowbreak training\_\allowbreak data}.

A table or figure that's too wide

A bad box isn't always in a paragraph. An image with a fixed width produces the same warning, and so does a tabular that's wider than the text column (for a table, the log says "in alignment at lines").

  • Images: set the width relative to the text, \includegraphics[width=\linewidth]{…}, never in centimetres. That's what Luzbase's Insert figure does by default.
  • Tables: use tabularx with an X column for the long text, so the table is exactly \linewidth wide and the text wraps inside it:
\usepackage{tabularx}
...
\begin{tabularx}{\linewidth}{lX r}

Avoid \resizebox on tables. It shrinks the font to an arbitrary size that won't match the rest of the paper.

One line that prevents most of them

Before fixing warnings one by one, add microtype to your preamble:

\usepackage{microtype}

It lets LaTeX adjust letter widths and margins by tiny, invisible amounts, which gives it many more ways to fill a line. In a typical paper it removes a large share of the overfull boxes on its own, and the text looks better too. It works with pdfLaTeX and LuaLaTeX, and partly with XeLaTeX.

Last resorts

If a paragraph still won't behave, you have two blunter tools:

\setlength{\emergencystretch}{3em}  % in the preamble

This gives LaTeX extra stretch to use only when it would otherwise produce an overfull line. It's a good default and rarely makes text look worse.

\sloppy goes further and allows very loose lines. Use it inside a group around one problem paragraph, never for the whole document:

{\sloppy
The dataset is available at \url{https://data.example.org/...}.
\par}

And sometimes the right fix is editing, not typesetting: swap two words, or rephrase the sentence. A copy editor would do the same.

What about Underfull \hbox?

It's the opposite problem: a line with too little text, where the spaces had to stretch further than LaTeX likes. You'll see Underfull \hbox (badness 10000). The most common cause is using \\ to end a paragraph or to add space. Use a blank line to start a new paragraph and \medskip or \vspace for space, and most of these go away. The rest are usually safe to ignore.

Quick checklist

  • Under 1pt: ignore it. Over 3pt: fix it.
  • \usepackage{microtype} first.
  • URLs in \url{} with xurl loaded.
  • Long formulas in a display, not inline.
  • breaklines=true for code listings.
  • Widths relative to \linewidth, tabularx for wide tables.
  • \setlength{\overfullrule}{5pt} to see them in the PDF, removed before you submit.

Start writing free.