3

I am getting an Overfull \hbox error and I've managed to trim the original big complicated file to this simple source that shows the problem:

\documentclass{article}
\begin{document}

\parindent=0pt changed systematically, and the intensity that manages to survive passage through

\end{document}

When I compile this using pdflatex myfile.tex I get:

Overfull \hbox (6.77846pt too wide) in paragraph at lines 5--6
[]\OT1/cmr/m/n/10 changed sys-tem-at-i-cally, and the in-ten-sity that man-ages
 to sur-vive pas-sage through

I've tried it with both MikTex and TexLive and I get the same error on both. I cannot understand what is going on. Why doesn't Latex break the line before the word "through" instead of overflowing the right margin and reporting an error, and how can I fix this?

I did a default install on Windows 10 and MikTex has picked up the regional settings and set the paper size to A4. I mention this because presumably a different paper size would change the line length and probably change the output. If it is relevant the MikTex settings look like this:

Settings

2 Answers2

2

User202729 has answered this in a comment, but given that comments are potentially ephemeral I will post it as an answer.

When LaTeX is justifying text it will not let the white space between words expand too much. Where a line contains a few long words, justifying the text might require the spaces between the words to be increased to a point where they look odd. If this happens LaTeX will instead let the line overflow the right margin and this generates the overfull hbox error.

The easy fix is to bracket the offending paragraph between:

\begin{sloppypar}

and

\end{sloppypar}

as this specifies that the spaces between words can be expanded as necessary to justify the text.

1

Leave solving overfull lines for the very last phase of document production, because even minimal changes to the text might solve the issue.

You have several strategies available, the main one is rewording. Nobody is like Mozart who allegedly was able to write down a complete piece with orchestration and all in a single work session: reread your paragraphs and quite likely you'll find some weak point or, at least, different wording to express the same thing without the paragraph being badly typeset.

Remove or add an adjective; place a missing comma, remove one too much; add a tie ~ to keep some words together. There are many other possibilities.

If all else fails, there are other tools available without resorting to the ultimate weapon sloppypar. I find it convenient to locally set \emergencystretch without touching \tolerance like sloppypar does. Here's a comparison.

\documentclass{article}
\begin{document}

\parindent=0pt

  1. overfull

\medskip

changed systematically, and the intensity that manages to survive passage through changed systematically, and the intensity that manages to survive passage through changed systematically, and the intensity that manages to survive passage through

\bigskip

  1. not overfull

\medskip

changed systematically, and the intensity that manages to survive passage through changed systematically, and the intensity that manages to survive passage through changed systematically, and the intensity that manages to survive passage through {\setlength{\emergencystretch}{0.5\textwidth}\par}

\bigskip

  1. sloppy

\medskip

\begin{sloppypar} changed systematically, and the intensity that manages to survive passage through changed systematically, and the intensity that manages to survive passage through changed systematically, and the intensity that manages to survive passage through \end{sloppypar}

\end{document}

enter image description here

The trick I used is to issue \par in a group where \emergencystretch is set to a nonzero value. The } brace after \par ensures that this setting won't carry over for the rest of the document.

You can see that my trick better distributes badness across all lines, rather than concentrate it in the first line like in the sloppypar case.

Take your time to solve each overfull and your document will look perfect. But I emphasize once again that rewording is the best approach in the vast majority of cases.

egreg
  • 1,121,712