How to Fix Overfull and Underfull Hbox Warnings
See what TeX's box warnings mean, find the affected paragraph, and choose a targeted fix for long URLs, equations, tables, or forced line breaks.
Summary: An overfull hbox contains material that is too wide; an underfull hbox could not be spaced well. They are typesetting warnings, not normally fatal errors. Locate the affected output and fix the specific content before changing global spacing.
What an hbox warning means
TeX builds lines from horizontal boxes. An overfull box extends beyond the width available for it, often into a margin. An underfull box has poor spacing because TeX could not form a satisfactory line under the current constraints.
Overfull \hbox (12.4pt too wide) in paragraph at lines 48--50
Underfull \hbox (badness 10000) in paragraph at lines 72--73
The first value tells you how far content exceeds the available width. Underfull “badness” describes how unsatisfactory TeX found the spacing. The PDF can still compile, so the decision depends on visible output rather than the message alone.
Find the affected content
- Open the compiler log and note the file and line range.
- Inspect the corresponding paragraph, table, equation, caption, or box in the PDF.
- Look for content that cannot break: a URL, code token, long word, wide formula, image, or table.
- For an underfull box, look for forced line breaks or very narrow justified text.
During local diagnosis, the document-class draft option can mark overfull lines with a rule. Remove diagnostic draft settings before the final submission if the receiving instructions require it.
Fix a long URL
Plain text URLs contain long sequences with few normal word breaks. Use a link command designed to permit sensible break points.
\usepackage{hyperref}
Read the project notes at
\url{https://example.org/research/a-very-long-project-path}.
The maintained hyperref documentation explains URL and link handling. Avoid inserting arbitrary spaces into an address because that can change the destination.
Fix a wide equation structurally
A long display equation should usually be split at meaningful mathematical relations rather than scaled until it is unreadable.
\usepackage{amsmath}
\begin{align}
L(\theta)
&= \sum_{i=1}^{n} \log p(y_i \mid x_i, \theta) \\
&\quad - \lambda \lVert \theta \rVert_2^2.
\end{align}
Choose align, multline, or another documented environment according to the equation's logic. Do not break a formula at a point that hides its meaning.
Keep images within the available line width
An image width based on \textwidth can be too wide inside a list, minipage, or column. \linewidth follows the width available in the current context.
\usepackage{graphicx}
\begin{figure}
\centering
\includegraphics[width=\linewidth]{figures/result.png}
\caption{Measured and predicted values.}
\end{figure}
Check the rendered size and legibility. A technically fitting image can still contain labels too small to read.
Repair tables instead of shrinking them blindly
First shorten headings, allow descriptive columns to wrap, or move secondary detail out of the table. The tabularx package can allocate a wrapping column across a requested width.
\usepackage{tabularx}
\begin{tabularx}{\linewidth}{lX}
Measure & Explanation \\
Precision & Fraction of predicted positive items that are correct. \\
\end{tabularx}
Scaling an entire table can make text inconsistent or inaccessible. Landscape pages and smaller type are options only when the document rules and readability justify them.
Remove unnecessary forced line breaks
An underfull warning often appears when \\ forces a short line inside a normal paragraph. Use a blank source line to begin a new paragraph. Use sectioning commands for structure, and reserve \\ for contexts where a line break is genuinely part of the layout.
% Fragile paragraph layout
This is a short line.\\
The paragraph continues here.
% Two real paragraphs
This is the first paragraph.
The next paragraph begins here.
Use global relaxations cautiously
Commands such as \sloppy, large \emergencystretch, \hfuzz, or high \hbadness can reduce or hide warnings. They do not explain the cause and can make spacing worse across the document.
A small, deliberate setting may be appropriate after you inspect the output, but try targeted fixes first: rephrase one sentence, add a valid discretionary hyphen, use the correct URL command, split one equation, or redesign one table.
| Cause | First targeted fix | Avoid as the first response |
|---|---|---|
| Long URL | \url{...} with a documented package | Manual spaces inside the address |
| Wide equation | Break at meaningful relations | Unreadable global scaling |
| Wide image | Use an appropriate \linewidth | Ignoring clipped labels |
| Wide table | Wrap or simplify columns | Shrinking every table |
| Short forced line | Remove unnecessary \\ | Suppressing underfull messages globally |
When can a warning be left alone?
A minor underfull warning can be harmless if the output has natural spacing. A very small overfull amount may also be visually acceptable depending on the glyph and document rules. Inspect the exact page at a useful zoom and follow the publisher or institution's requirements. Do not assume every warning must be silenced, and do not assume every successful PDF is well typeset.
Final check
Compile the root document, inspect every affected page edge, and confirm that a fix did not create a new break elsewhere. For syntax failures that prevent a PDF, begin with the common compilation error checklist. The LaTeX2e reference manual hosted by the TeX Users Group also documents line breaking, boxes, and core commands.