8

I'm trying to troubleshoot an overfull hbox warning that arises with some long chapter titles in memoir. I've narrowed it down to the following minimal example. The problem arises with mathptmx but not with CM. Also, the overfull box is not really real, since there is nothing overlapping the actual margin, but I would like to know how to remove the warning nonetheless, since this code is actually part of a custom document class.

\documentclass[draft,12pt]{memoir}
\usepackage{mathptmx} % comment out to remove the overfull box
\settypeblocksize{9in}{6.5in}{*}
\setlrmargins{1in}{*}{*}
\setulmargins{1in}{*}{*}
\setheadfoot{\baselineskip}{.5in}
\checkandfixthelayout
\makeatletter
\renewcommand*{\l@chapter}[2]{%
  \l@chapapp{\MakeUppercase{#1}}{#2}{\cftchaptername}}
\makeatother
\renewcommand*{\cftchaptername}{Chapter\space}

\setlength{\cftchapternumwidth}{3em}
\setrmarg{3.5em} % better wrapping of long titles
\makeatother

\begin{document}
\frontmatter
\tableofcontents*
\mainmatter

\chapter{A chapter with a really long title to see whether the chapter titles wrap correctly}
\end{document}

TOC fragment

3
  • mathptmx change the font ;-) YOu can see the wrong hyphen by: \chapter[A chapter with a really long title to see whet\-her the chapter titles wrap correctly] {A chapter with a really long title to see whether the chapter titles wrap correctly} -- This is one solution. The other one: \begingroup \sloppy \tableofcontents* \endgroup May 27, 2012 at 19:40
  • The warning is I think real, there is fixed space taken from either side for "Chapter 1" and the page number, and the renaming text can't be wrapped in the remaining space. May 27, 2012 at 22:43
  • Your remark about not happening with CM is not true; if you use CM with all your other settings, and this title: \chapter{A chapter with a really long title whether the chapter titles wrap correctly}, you will also get an overfull \hbox I did some tests and apparently TeX has a hard time hyphenating "whether". May 28, 2012 at 3:33

1 Answer 1

8

The overful box arises in the Table of Contents.

If you set the length of \cftchapternumwidth to a smaller value

  \setlength{\cftchapternumwidth}{2.25em}

it goes away.

The reason why you thought it was dependent on the font was that the word "whether" is placed on the first line with the mathptmx, where it is put on the next line with the default CM font; and the real culprit of course is that "whether" is not normally hyphenated. (See images below).

enter image description here

enter image description here

It is interesting to measure the dimensions of the word "whether" in both fonts. The "palatino" font is a much narrower font and measures 32.2097pt; whereas the CM measures 35.02783pt, which is about 7% wider. From a readability point of view this is better as it tends to have less letters on a line and for most LaTeX documents our lines are too long.

6
  • But then the problem will reappear for some other title (for example, \chapter{A chapter with a really looong title to see whether the chapter titles wrap correctly}). I think this is just a problem with the hyphenation of "whether" and should be treated as such and no special modification to the current settings is needed. May 28, 2012 at 4:26
  • @GonzaloMedina Sure, the reason I suggested a smaller value was to reduce the risk and the value seemed a bit high. May 28, 2012 at 5:30
  • Thanks for the explanation. I did realise that the font itself wasn't causing the problem. Reducing the chapter num width isn't really an option; it never occurred to me that one particular common word would cause hyphenation problems.
    – Alan Munn
    May 28, 2012 at 14:36
  • @AlanMunn The mysteries of tex:) To be honest, personally I don't worry for overfull boxes, if I cannot see them in a normal run (i.e. not in demo mode where the overflow line gives a clue). May 28, 2012 at 14:43
  • I agree, in practice. But since this was in the sample document for my thesis class it seemed bad form to have it compile with a warning, especially when the documentation says "get rid of them". :)
    – Alan Munn
    May 28, 2012 at 14:53

You must log in to answer this question.

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