1

I got a problem with my current document. Some of the Section titles are fairly long and the linebreak won't work in the table of contents. For some reason it works when I compile it with texstudio. (where other stuff won't work) But when I compile it with texcenter and the profile LaTeX-PS-PDF it will produce a toc wich just looks horrible.

\documentclass[
12pt,
footheight=22pt,
openright,
a4paper,
twoside,
listof=totoc,
bibliography=totocnumbered,
final]{scrbook} 

\usepackage{scrhack}
\usepackage{geometry}
\geometry{inner=2.5cm, outer=5cm, head=22pt}
\raggedbottom           
\frenchspacing
\usepackage[ngerman,english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc} 
\usepackage{lmodern}
\usepackage{amsmath, amssymb, amsfonts, pifont, float, color,setspace}
\usepackage{notoccite} %keeps cite numbers from text in toc...
\usepackage{graphicx}
\usepackage[format=plain,justification=justified,singlelinecheck=false,font={stretch=1.125,small,sf},labelfont=bf,labelsep=space]{caption}
\usepackage[section]{placeins} %keeps floats in section
\usepackage[pdfpagelayout=TwoColumnRight,colorlinks=false, pdfborder={0 0 0}, bookmarksnumbered=true]{hyperref}
\usepackage[hyphenbreaks]{breakurl}
\usepackage{footnote}
\usepackage{tabularx}
\makesavenoteenv{tabular}
\captionsetup{width=.9\textwidth} %90% textwidth for all captions
\usepackage{psfrag}
\usepackage[right]{eurosym}
\usepackage[super,square,comma,sort&compress]{natbib} %hochstellen des cite befehls
\usepackage[version=3]{mhchem}
\apptocmd{\thebibliography}{\raggedright}{}{}%url formatting in biblio
\usepackage{verbatim}
%list of figures spacing
\makeatletter
\renewcommand*\l@figure{\@dottedtocline{1}{1em}{3.2em}}
\makeatother
\usepackage[final]{listings}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage[headsepline,footsepline]{scrlayer-scrpage}
\automark[section]{section}
%\renewcommand*{\partmark}[1]{}
\setkomafont{pageheadfoot}{\normalcolor\footnotesize\scshape}
\setkomafont{pagenumber}{\normalfont\normalsize}
\clearpairofpagestyles
\ihead{\scriptsize\headmark}
\ohead*{\pagemark}

\clubpenalty = 100000
\widowpenalty = 100000
\displaywidowpenalty = 100000
\interlinepenalty=5000 %dont break sentences

%Zeilenabstand
\linespread{1.5}

\begin{document}
    \tableofcontents
    \addtocontents{toc}{\protect\enlargethispage{0.5cm}}
    \chapter{Chapter 1}
    \section{Section with a really really really long title I mean really really long title}
    \subsection{Even worse title for a subsection once you finished reading you feel like you read a book}
\end{document}

Table of contents no linebreaks

Has anyone an idea how I can fix it?

3
  • 2
    Welcome to TeX SX! You can use the optional argument of \section to usr a short version of the section title, both in headers and in the table of contents.
    – Bernard
    Commented Jan 29, 2020 at 15:40
  • As you state, in texstudio it works. Maybe you should try to get the other things working in texstudio? Also, why not use shorter titles?
    – Sango
    Commented Jan 29, 2020 at 15:42
  • 1
    Please reduce your example, most of your preamble is irrelevant for this problem. Only hyperref and breakurl is relevant. Exactly which ghostscript version are you using. Exactly how are you compiling i texstudio? The MWE has no issues with pdflatex only the latex+dvips+ps2pdf route
    – daleif
    Commented Jan 29, 2020 at 15:54

2 Answers 2

4

The dvips driver can't break links (this will perhaps change but not directly).

If you insist on the latex->ps route you can use the option breaklinks. This is okay for printing, but the linkarea will be wrong:

\documentclass[]{scrbook}

\usepackage[breaklinks]{hyperref}
\usepackage{breakurl}


\begin{document}
    \tableofcontents
    \chapter{Chapter 1}
    \section{Section with a really really really long title I mean really really long title}
    \subsection{Even worse title for a subsection once you finished reading you feel like you read a book}
\end{document}

enter image description here

A better option (and the one recommended in the documentation of hyperref) is linktocpage which will put the links on the page numbers:

\usepackage[linktocpage]{hyperref}

enter image description here

1
  • ahh, I couldn't spell, was looking for a breakurl option for hyperref
    – daleif
    Commented Jan 29, 2020 at 16:20
0

The LaTeX sectioning commands all take an optional argument as well as the required one. If the optional argument is used then that will be used for the ToC and any page headings entries and the required argument for the section title in the document; otherwise the required argument is used for all three places.

\section[Short ToC entry]{Long main document title entry}
1
  • thanks the linktocpage command was what I was looking for. Commented Jan 30, 2020 at 10:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .