12

I'm writing a pretty long document, and at some point this happened with the table of contents:

I would like to be able to force a line break between 'complex' and 'space', either directly or by imposing suitable limits on line lengths or the separation between the lines and the numbers, or any such relevant lengths.

A minimal working example is below,

\documentclass[pdftex,11pt,twoside,a4paper]{report}

\usepackage[a4paper, left=3cm, right=3cm, top=3cm, bottom=2cm]{geometry}
\usepackage[T1]{fontenc}
\usepackage{lmodern} % load a font with all the characters
\usepackage[colorlinks,linkcolor=blue,final]{hyperref}
\usepackage{tocloft}

\usepackage{lipsum}


%%% Headers
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\setlength{\headheight}{14pt} 
\fancyhead[LE]{\thepage}
\fancyhead[RE]{Electron dynamics in complex space and complex time}
\fancyhead[LO]{\nouppercase{\leftmark}}
\fancyhead[RO]{\thepage}

\renewcommand{\chaptermark}[1]{\markboth{\thechapter.\ #1}{}}


\begin{document}

\tableofcontents  
\setcounter{page}{100}
\chapter{Quantum orbits as trajectories through complex time and complex space}
\lipsum[1-16]

\end{document}

including the headers in use in the document; obviously all of the non-lipsum packages are necessary in the larger document. How can I fix this ugliness?

Werner
  • 603,163
E.P.
  • 1,415
  • But you don't want this happening in the header. What do you use to create your header? – Werner Sep 07 '16 at 17:40
  • @Werner See edited post with the headers in use. – E.P. Sep 07 '16 at 17:44
  • 1
    @E.P. Why not using \chapter[Quantum orbits as trajectories]{Quantum orbits .... long title}??? Such long titles appear in the headers too, unless you would use memoir where you can specify the header title too, in addition to the ToC entry and the heading title –  Sep 07 '16 at 17:51
  • @ChristianHupfer The title fits perfectly in the header, and I would quite like to keep the longer title in the table of contents as the information you've chopped off does matter ;-). It is perfectly possible for the chapter title to have a line break in the TOC, which you get e.g. by removing the fontenc package. What I want works, it's just LaTeX trying to bully me into thinking it knows better, even though it demonstrably knows better than what it is saying now that it thinks it knows better. – E.P. Sep 07 '16 at 18:23

1 Answers1

9

You could specify your chapter using

\chapter[Quantum orbits as trajectories through complex time and complex \texorpdfstring{\\}{} space]% ToC/Header
  {Quantum orbits as trajectories through complex time and complex space}% Document
% Correct header setup to not insert a line break
\markboth{\thechapter.\ Quantum orbits as trajectories through complex time and complex space}{}

The optional argument to \chapter sets the ToC and header entries. So we replicate the usual \chaptermark to correct for inserting a line-break inside the header.

Alternatively, increase the page number width inside the ToC and/or set the alignment of chapter-related entries to include a \raggedright alignment:

\cftsetpnumwidth{3em}% Default is 1.55em
\cftchapfont{\bfseries\raggedright}% Default is \bfseries

enter image description here


memoir provides the option of explicitly setting all three possibilities via

\chapter[<toc>][<head>]{<title>}
Werner
  • 603,163
  • 3
    Wouldn't it be better to configure the toc with a larger space for the page numbers and setting the titles ragged right like. The op is already using tocloft – daleif Sep 07 '16 at 18:14
  • Yeah, I tried that, but it raises a hyperref warning (token \ not allowed) which I'd rather not have without good reason. And, as daleif said, I'm already using tocloft, which should provide enough customizability to do what I need. (Unfortunately, the tocloft documentation is, as usual, beautifully typeset and completely impenetrable to anyone but the package maintainer.) – E.P. Sep 07 '16 at 18:31
  • 1
    @E.P.: I've added the use of \texorpdfstring to distinguish between TeX and PDF-related content. That takes care of the hyperref warning (due to the PDF bookmarks). I'll update my answer to include a tocloft adjustment as well. – Werner Sep 07 '16 at 18:37
  • Yeah, that's probably plenty good. For future googlers it's probably best to include a tocloft fix, though. – E.P. Sep 07 '16 at 18:59