35

Here is a short file which produces an overfull hbox:

\documentclass[12pt]{report}
\usepackage[left=1.5in,right=1in,paperwidth=8.5in,paperheight=11in]{geometry}
\begin{document}
\trivlist
\item[\hskip\labelsep{\bf2.3.12 Corollary [Isomorphisms are indexed bijections]:}]
Consider the functions $f$ and $g$
\endtrivlist
\end{document}

If I replace functions with func-\linebreak tions, the word is split across two lines, resulting in neither an overfull nor an underfull hbox. However, neither func\-tions nor func-tions produces this behavior. Why not? Is there a better way to convince TeX that it's okay to hyphenate this word to prevent an overfull box?

3
  • If you load microtype, the overfull box will be reduced from 10.7pt to 8.5pt.
    – Sverre
    Mar 30, 2014 at 18:09
  • You may want to try and put \emergencystretch=.5em into the preamble. \sloppy is way too harsh.
    – morbusg
    May 16, 2014 at 20:28
  • Aside: The use of {\bf ...} in LaTeX documents is deprecated, and it no longer works at all depending on the document class that's in use. Use {\bfseries ...} or \textbf{...} instead.
    – Mico
    Jan 12, 2018 at 1:22

1 Answer 1

42

It's important to remember that TeX doesn't build a page line by line, but paragraph by paragraph. This is a major difference from the behavior of most word processing programs.

TeX applies various rules -- resulting in penalties or demerits if they're not satisfied -- to come up with an "overall best" appearance of a paragraph. TeX assigns penalties not only to overfull lines but also to irregular inter-word spaces. Specifically, TeX will try very hard to produce roughly the same amount of interword space across all lines of a paragraph, and it tries to keep the amount of interword space fairly "tight" by default. TeX does so by assigning substantial penalties if the amount of interword space varies noticeably across lines within one and the same paragraph and also if there's too much whitespace between words.

In the example you've provided, the unhyphenated word "functions" happens to protrude by "only" two characters ("ns") into the right-hand margin. In TeX's view, this outcome appears to be preferable to hyphenating the word "functions", as hyphenating the word would also generate two very large interword spaces -- between "Consider" and "the" as well as between "the" and "functions. (TeX isn't allowed to adjust any of the interword spaces between the words that are in the argument of \item, because that "box" has already been closed and is no longer modifiable by TeX's paragraph building routine. As a result, there are only two interword spaces in the first line that TeX is allowed to modify while it's building the paragraph.)

To override TeX's default settings related to building paragraphs, one could issue the command \sloppy. Sure enough, as is shown in the code and screenshot below, if one inserts the instruction \sloppy before \item, TeX has no problem hyphenating the word "functions"; the cost is the creation of two rather large interword gaps in the first line of the paragraph. (If you don't want to go quite as far as \sloppy, you might try typing \tolerance=1000. The default value of \tolerance is 200. See pp. 29f. of the TeXbook for more information on this parameter.)

A different, and in my view much better, solution starts by recognizing that the real cause of the overfull-line issue is that TeX is initially being given only two interword gaps to adjust. Limiting the scope of \item and placing \textbf{[Isomorphisms are indexed bijections]:} after \item[\hskip\labelsep{\bfseries 2.3.12 Corollary}] creates many more ``degrees of freedom'' for TeX's paragraph-building algorithm. This immediately leads to a much more satisfying solution, as is also shown in the screenshot below. (The black frame lines are inserted courtesy of the showframe option of the geometry package.)

Finally, yet another solution, which may or may not be to your liking, is to forgo full justification: load the package ragged2e and issue the command \RaggedRight to allow hyphenation. Without full justification, you're virtually assured that there will be no overfull lines.

In summary, the problem you describe arises because (i) TeX has only 2 interword spaces to play with on the first line and (ii) TeX generally assigns fairly high penalties to irregular and large values of interword spaces. In the case of your example, these penalties appear to outweigh the penalty created by letting a word protrude slightly beyond the right-hand edge of the text block. To solve the issue, you could either use \sloppy or simply give TeX's paragraph-building algorithm more degrees of freedom (by limiting the scope of the \item directive).

enter image description here

\documentclass[12pt]{report}
\usepackage[left=1.5in,right=1in,
  paperwidth=8.5in,paperheight=11in,
  showframe,nomarginpar]{geometry}
\setlength\parindent{0pt} % just for this example
\begin{document}

Initial (``tight'') setting---overfull line.
\trivlist
\item[\hskip\labelsep{\bfseries 2.3.12 Corollary 
  [Isomorphisms are indexed bijections]:}]
Consider the functions $f$ and $g$
\endtrivlist

\medskip
\begingroup
Solution 1: Use \verb+\sloppy+ directive---not great.
\sloppy
\trivlist
\item[\hskip\labelsep{\bfseries 2.3.12 Corollary   
  [Isomorphisms are indexed bijections]:}]
Consider the functions $f$ and $g$
\endtrivlist
\endgroup

\medskip
Solution 2: Limit extent of argument of \verb+\item+---best.
\trivlist
\item[\hskip\labelsep{\bfseries 2.3.12 Corollary}] 
  \textbf{[Isomorphisms are indexed bijections]:}
Consider the functions $f$ and $g$
\endtrivlist

\end{document}
5
  • 4
    I think it's not just to say TeX "prefers" overfull boxes. It certainly doesn't generate them with the intent to have words dangling over the boundary in any final print document. — I would take it that TeX prefers to give a definite warning, both as a message and as a visible feature in the output, so you can manually adjust your document to avoid either problem. If Tex just kept inserting big spaces, you wouldn't notice but the output would be ugly. Since it's only a warning (which you may ignore), this is still compatible with the focus-on-content-rather-than-presentation philosophy. Mar 30, 2014 at 12:31
  • 1
    @leftaroundabout - Well, the claim about TeX "preferring" an overfull box to hyphenating a word is in the posting's title, not my answer. I use the (admittedly somewhat related...) expression "preferable" merely as a way of setting up the outcome of the choice TeX has to make between two not-so-great outcomes when building the paragraph: creating an overfull box on the one hand, vs. having very uneven spacing between words on the other.
    – Mico
    Mar 30, 2014 at 12:42
  • Can I ask for slightly larger spaces in the trivlist label somehow? (Should I open a separate question for that?) Mar 30, 2014 at 14:10
  • 1
    @DanielWagner - May I suggest you post a new question (to inquire about how to get LaTeX to operate on the interword spaces inside an item's "label")? That way, more people will see it and have a chance to provide an answer. Thanks.
    – Mico
    Mar 30, 2014 at 15:36
  • 1
    For posterity, I found that playing with \spaceskip in the label produced the effect I wanted: greater interword spacing along the whole line, and a hyphenated final word. Mar 30, 2014 at 22:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .