Usually line breaks are permitted in the table of contents.
Example from Marco Daniel:
\documentclass{report}
\usepackage{blindtext}
\begin{document}
\tableofcontents
\chapter{Really Really Really Really Really Really Really Really Really Really Really Long Text}
\Blinddocument
\end{document}
Package hyperref
If you are using package hyperref
with a driver that does not support broken links across lines, then option linktocpage
helps. That allows line breaks in the title and the link is put to the page number instead.
Example file:
\documentclass{report}
\usepackage[colorlinks,linktocpage]{hyperref}
\begin{document}
\tableofcontents
\thispagestyle{empty}
\chapter{Really Really Really Really Really Really Really Really Really
Really Really Long Text}
\end{document}
Other classes packages
My guess with package hyperref
can be wrong, the screen shot in the question does not show hyper links and the chapter title is set in all uppercase letters, perhaps the questioner is using a special class or package that deals with the table of contents that prevents line breaks.
Justification
Or line breaks are permitted and the effect is just an ordinary overfull \hbox
because TeX cannot find a good break point.
The optimal way to handle this would be use a macro (for convenience and consistency) and adjust \emergencystretch
to suit your needs:
\documentclass{article}
\usepackage{pgffor}
\pagestyle{empty}
\usepackage[paper=a6paper,paperheight=.25\paperheight]{geometry}
\newlength{\BRANDNAMElen}
\settowidth{\BRANDNAMElen}{BRANDNAME}
\setlength{\emergencystretch}{1.1\BRANDNAMElen}% \emergencystretch is slightly longer than \BRANDNAMElen
\newcommand{\BRANDNAME}{\mbox{BRANDNAME}}
\begin{document}
\setlength{\emergencystretch}{5em}
\foreach \x in {\unskip,s,si,sit,sit{ },
sit a,sit am,sit ame,sit amet,sit amet{ },
sit amet c,sit amet co,sit amet con,sit amet cons,
sit amet conse,sit amet conset,sit amet consete,
sit amet consetet,sit amet consetetu,sit amet consetetur,
sit amet consetetur{ },sit amet consetetur l,sit amet consetetur lo,
sit amet consetetur lor,sit amet consetetur lore,sit amet consetetur lorem,
sit amet consetetur lorem{ },sit amet consetetur lorem i,sit amet consetetur lorem ip,
sit amet consetetur lorem ips,sit amet consetetur lorem ipsu,sit amet consetetur lorem ipsum,
sit amet consetetur lorem ipsum,sit amet consetetur lorem ipsum,sit amet consetetur lorem ipsum,sit amet consetetur lorem ipsum,sit amet consetetur lorem ipsum,sit amet consetetur lorem ipsum,sit amet consetetur lorem ipsum,sit amet consetetur lorem ipsum,sit amet consetetur lorem ipsum,sit amet consetetur lorem ipsum} {
\clearpage
Lorem ipsum dolor \x{} \BRANDNAME{}
sadipscing elitr, sed diam nonumy eirmod tempor
invidunt ut labore et dolore magna aliquyam erat,
sed diam voluptua. At vero eos et accusam et justo
duo dolores et ea rebum.
}
\end{document}
The above macro inserts letters around \BRANDNAME
(set as an unbreakable \mbox
) to identify whether the break would flush it to the following line. \emergencystretch
is set to 10% more of the width of \BRANDNAME
to allow for the line-breaking algorithm to check a third time during paragraph setting whether adjustments should be made.
You may have to reset \emergencystretch
to 0pt
when you don't need it.
During paragraph assembly, TeX attempts (perhaps multiple times) to lay out the lines in an optimal way.
Read TeX by Topic, specifically section 19.2 The process of breaking (p 179). Here is an excerpt:
19.2.1 Three passes
First an attempt is made to split the paragraph into lines without hyphenating, that is, without inserting discretionary hyphens. This attempt succeeds if none of the lines has a
badness exceeding \pretolerance
.
Otherwise, a second pass is made, inserting discretionaries and using \tolerance
. If
\pretolerance
is negative, the first pass is omitted.
TeX can be made to make a third pass if the first and second pass fail. If \emergencystretch
is a positive dimension, TeX will assume this much extra stretchability in each line when badness and demerits are calculated. Thus solutions that only slightly exceeded the given tolerances will now become feasible. However, no glue of size \emergencystretch
is actually present, so underfull box messages may still occur.
Best Answer
Note: This answer has been thoroughly edited (by its original author) in order to straighten it.
As it happens, the way in which the standard book class, or the LaTeX kernel, implement the
\l@chapter
command, or, respectively, the\@dottedtocline
command, makes it possible that such unfortunate line breaks may occasionally occur in the table of contents (or in similar tables, like the list of figures). The problem is not apparent unless the width of the referred-to page number is wide enough.To clarify the source of the problem, consider first the following simple example, in which the standard book class is used (but the same discussion applies to other classes as well, including scrbook):
It produces the following output:
Compare it with the output produced by the following possible patch (which again, is suitable for the standard
book
class):Here it is:
As you see, the additional
.5em
of space inserted between the text of the entry and the page number forces the desired line break.Of course, this patch is pretty pointless, since it is much simpler, and more general, to adjust
\@pnumwidth
, as we do in the following code:Result:
However, one might object that, in order to make more room for the page number, this solution causes the leaders (the “dots”) to stop earlier across the line. This shouldn’t be a problem, but if it is, yet another remedy is feasible, which is illustrated below. Note that, in this case, it is the
\@dottedtocline
command that needs to be patched (as well), since leaders occur only in entries for sections and lower level headings, which are produced via this command. Note also that, in order to show that the patch actually works, the dots has been made closer to one another in this example.The output from this last example:
It should be stressed that the first and the last patch cannot be blindly applied to document classes other than book, or when particular packages are being used; the second one, on the other hand, has better chances to work under more general circumstances.
Finally, I think it is worth mentioning that the issue we are talking about is not addressed by the fixltx2e package.