For all of LaTeX’s obvious charm, longtime users know that you still run into formatting issues from time to time. One such issue is how LaTeX has trouble handling line breaks (or line wrapping) in table of contents pages, which also applies to list of figures and list of tables pages. Here is what you might see:
Note Figure 3.1 (The Drucker-Prager hyperbolic…), which violates the right margin. It’s not just that it’s improperly aligned—sometimes entries like this will march right off the page. You don’t have to stand for this.
It turns out this arises from a problem with the hyperref
package’s ability to insert a line break inside a link. Since I am using hyperref
to make all TOC entries clickable (which is why the list is blue in the image above), if the caption is too long, it doesn’t know what to do.
You can fix this issue by adding the option linktocpage
to your hyperref
stack. The tradeoff is that the list text is no longer linked; just the page number. Not ideal, but worth it to close this ticket without significantly altering the functionality of the TOC. Here’s the new output:
There, much better.
A few final notes:
- The
hyperref
optionbreaklinks
is supposed to fix this issue, but was unsuccessful for me. - Some people actually suggest shorter captions as the solution to this problem. As Tufte would say, this is letting the cognitive style of your tool, not your message, drive the bus.
- You can always use the
caption[Short caption]{Long caption}
format, which only inserts the portion in the [ ] in the TOC (works identically for caption/section/subsection/etc). This is how I’ve always corrected this problem in the past. I will still use it for really long entries, but would rather not worry about dual-captions for entries at or near a single line length.