Fix overfull and underfull \hbox warnings in LaTeX
These are warnings, not errors: your PDF still builds. An overfull box is a line that sticks out into the margin. An underfull box is a line LaTeX had to stretch more than it likes. You will learn when to fix them and how.
The message
Section titled “The message”Overfull \hbox (128.41269pt too wide) in paragraph at lines 3--4Underfull \hbox (badness 10000) in paragraph at lines 5--6The line numbers tell you which paragraph of the source to look at. For an overfull box, the number in brackets says how far the line sticks out: a few points is barely visible, more than that usually is.
Why it happens
Section titled “Why it happens”Overfull boxes:
- A long word, URL, file name or piece of code that LaTeX cannot hyphenate or break.
- An image or table wider than the text, for example
\includegraphics[width=20cm]{…}.
Underfull boxes:
- A forced line break
\\at the end of a paragraph or followed by a blank line. - Several
\\in a row, or\\used to add vertical space. - A narrow column, where LaTeX has few places to break lines.
Example
Section titled “Example”\documentclass{article}\begin{document}\noindent See \texttt{https://example.org/a/very/long/path/that/cannot/be/broken/anywhere/at/all/in/this/line} now.
First line of the address.\\
Second paragraph.\end{document}Let long URLs break, and end paragraphs with a blank line instead of \\:
\documentclass{article}\usepackage{xurl}\begin{document}\noindent See \url{https://example.org/a/very/long/path/that/cannot/be/broken/anywhere/at/all/in/this/line} now.
First line of the address.
Second paragraph.\end{document}Other fixes for overfull lines:
- Size images and tables relative to the text, for example
\includegraphics[width=\linewidth]{…}. - Rephrase the sentence, or tell LaTeX where a long word may break, for example
data\-base.
For vertical space, use \medskip, \bigskip or \vspace{…} instead of extra \\.
Finding them in Luzbase
Section titled “Finding them in Luzbase”Overfull and underfull boxes never stop a compile. They appear in the full log in the Output panel (click Show full log), and Luzbase marks the line in the editor with a subtle underline. You can ignore small ones; fix the ones you can see in the PDF.
Not on Luzbase yet? It compiles LaTeX in your browser and links each error to its line, often with the fix. Start writing free.