What do you mean by "customizing the ToC itself"? Why can't we just get this line break working?localghost wrote:What about either customizing the ToC itself or the page geometry?AleCes wrote:[…] This is no solution: if I remove\hbox{-}
, and leave a simple hyphen in place, the date will be split and that is unintended.
General ⇒ Error while using \linebreak inside a heading
Error while using \linebreak inside a heading
NEW: TikZ book now 40% off at Amazon.com for a short time.

- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Error while using \linebreak inside a heading
E.g. influencing the width of entries for the headings and thus the line breaks. But using geometry for other (more appropriate) page dimensions would also be a good start.AleCes wrote:What do you mean by "customizing the ToC itself"? […]
Good question. At the moment I have no straightforward solution.AleCes wrote:[…] Why can't we just get this line break working?
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Error while using \linebreak inside a heading
I can use geometry, but the layout is fine for me, I don't want to change it, actually I don't understand why
\\
works but \linebreak
doesn't. If some package somehow doesn't like line breaks, \\
should give me an error as well, but it doesn't!Error while using \linebreak inside a heading
BecauseAleCes wrote:[...] I don't understand why\\
works but\linebreak
doesn't. [..]
\linebreak
is a fragile command which in a moving argument such as a heading must be protected with \protect
while \\
is robust, i.e. it has been defined via \DeclareRobustCommand
. This has nothing to do with any package.Code: Select all
\documentclass{article}
\newcommand*\cs[1]{\texttt{\textbackslash#1}}
\begin{document}
\tableofcontents
% error:
% \section{A heading\linebreak with a \cs{linebreak}}
% works:
\section{A heading \protect\linebreak with a \cs{linebreak}}
% works:
\section{A heading \\ with \cs{\textbackslash}}
\end{document}
site moderator & package author
Re: Error while using \linebreak inside a heading
Thanks, cgnieder, it works! 
