GeneralError while using \linebreak inside a heading

LaTeX specific issues not fitting into one of the other forums of this category.
AleCes
Posts: 286
Joined: Sat Nov 13, 2010 9:54 pm

Error while using \linebreak inside a heading

Post by AleCes »

Hello everybody, I'm experiencing problems in using \linebreak inside a \chapter[]{}. Minimal example below:

Code: Select all

\documentclass[a4paper, 12pt]{book}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead{}
\fancyhead[CE]{{\leftmark}}
\fancyhead[CO]{{\rightmark}}
\usepackage{fontspec}
\defaultfontfeatures{Style=Alternate, Mapping=tex-text}
\setmainfont{FreeSerif}
\usepackage{polyglossia}
 \setmainlanguage{serbian}
\setotherlanguages{french, latin, english, german, croatian, italian}
\usepackage{xunicode}
\usepackage{xltxtra}
\usepackage{bookmark}
\raggedbottom

\usepackage[center]{titlesec}
\usepackage{enumitem}
\setlist{topsep=0pt}

\setlength{\headheight}{30pt}
\renewcommand*{\thesection}{\arabic{section}}

\begin{document}
\tableofcontents

\chapter[Оснивање Цариграда и постанак источног римског царства \linebreak  (330\hbox{-}518~г.)]{Оснивање Цариграда и постанак источног римског царства (330\hbox{-}518~г.)}

\end{document}
Error message:

Code: Select all

! Use of \@chapter doesn't match its definition.
\kernel@ifnextchar ...rved@d =#1\def \reserved@a {
                                                  #2}\def \reserved@b {#3}\f...
l.55 ...ог царства (330\hbox{-}518~г.)}}
                                                  
? 
Last edited by AleCes on Tue Jul 02, 2013 6:38 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

tom
Posts: 73
Joined: Thu Apr 18, 2013 4:02 am

Error while using \linebreak inside a heading

Post by tom »

You can break the line with \\. Not sure if that will fix the error you get.

Code: Select all

\documentclass[11pt]{report}
\begin{document}
\tableofcontents
\chapter[Some text\\some other text]{Some text\\some other text}
\end{document}
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Re: Error while using \linebreak inside a heading

Post by localghost »

Why do you want to force that line break at all in a heading? That's bad style.


Thorsten
AleCes
Posts: 286
Joined: Sat Nov 13, 2010 9:54 pm

Error while using \linebreak inside a heading

Post by AleCes »

tom wrote:You can break the line with \\. Not sure if that will fix the error you get.

Code: Select all

\documentclass[11pt]{report}
\begin{document}
\tableofcontents
\chapter[Some text\\some other text]{Some text\\some other text}
\end{document}
\\ doesn't justify the text, it just breaks the line.
AleCes
Posts: 286
Joined: Sat Nov 13, 2010 9:54 pm

Error while using \linebreak inside a heading

Post by AleCes »

localghost wrote:Why do you want to force that line break at all in a heading? That's bad style.


Thorsten
The break is intended for the TOC, because there's an overflow there, not for the heading.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Error while using \linebreak inside a heading

Post by localghost »

AleCes wrote:[…] The break is intended for the TOC, because there's an overflow there, not for the heading.
That's not the default behaviour. And you are not using hyperref by chance? If so, use its breaklinks option, which is described in Section 3.3 of the package manual.

If that doesn't help, prepare a self-contained and minimal example that exactly reproduces the undesired behaviour. There could be various other causes.
AleCes
Posts: 286
Joined: Sat Nov 13, 2010 9:54 pm

Error while using \linebreak inside a heading

Post by AleCes »

localghost wrote:
AleCes wrote:[…] The break is intended for the TOC, because there's an overflow there, not for the heading.
That's not the default behaviour. And you are not using hyperref by chance? If so, use its breaklinks option, which is described in Section 3.3 of the package manual.

If that doesn't help, prepare a self-contained and minimal example that exactly reproduces the undesired behaviour. There could be various other causes.
What do you mean by that? That by executing my minimal example you don't get the same error message as I do? And by the way, I use bookmark not hyperref, as you can see from my minimal example, which you seem to dismiss without even having taken a look at it.

P.S. Maybe you can't reproduce the error because the TOC is absent in the minimal example, I've now added the relevant command, please give it a try now.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Error while using \linebreak inside a heading

Post by localghost »

AleCes wrote:What do you mean by that? That by executing my minimal example you don't get the same error message as I do? And by the way, I use bookmark not hyperref, as you can see from my minimal example, which you seem to dismiss without even having taken a look at it. […]
Please accept my apologies. I mixed things up. I should really give up writing different posts simultaneously.
AleCes wrote:[…] Maybe you can't reproduce the error because the TOC is absent in the minimal example, I've now added the relevant command, please give it a try now.
The problem is fixed if you delete the \hbox commands in the heading.
AleCes
Posts: 286
Joined: Sat Nov 13, 2010 9:54 pm

Error while using \linebreak inside a heading

Post by AleCes »

localghost wrote: Please accept my apologies. I mixed things up. I should really give up writing different posts simultaneously.
Apologies accepted, don't worry, I know you have to put up with so many posts. ;)
localghost wrote: The problem is fixed if you delete the \hbox commands in the heading.
This is no solution: if I remove \hbox{-}, and leave a simple hyphen in place, the date will be split and that is unintended.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Error while using \linebreak inside a heading

Post by localghost »

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.
What about either customizing the ToC itself or the page geometry?
Post Reply