0

I have checked several other questions addressing similar issues as this one, but I am still not able to tweak my document the way I want.

I have this 2-line chapter title:

enter image description here

which looks awful in the TOC, spanning 3 lines:

enter image description here

I tried using \\ whichs partially does the trick in the TOC (I still need to find out how to place the first word in line 2 right under the first word from line 1), but adds an aditional line in the chapter title, which I do not want.

enter image description here

enter image description here

I am aware of the optional argument for \chapter[text in TOC]{Chapter title}, but I do not want to use 2 names for the same chapter.

I tried \chapter[Control Strategies for Wave Energy Converters: \\ State-of-the-Art]{Control Strategies for Wave Energy Converters: State-of-the-Art} which does the linebreak in the TOC where I want and fixes having the aditional line in the chapter title (I still need to find out how to place the first word in line 2 right under the first word from line 1). With the downside I get a warning "Package hyperref Warning: Token not allowed in a PDF string (Unicode): removing `\' on input line 180"

I tried also \texorpdfstring{}{} given by Gonzalo:

\chapter{ \texorpdfstring{Control Strategies for Wave Energy Converters:\\ State-of-the-Art}{Control Strategies for Wave Energy Converters: State-of-the-Art} }

but I get the same result as just using \\.

Any guidance?

Cheer!

Here is the whole "MWE" (sorry, maybe no so minimum):

\documentclass[twoside,12pt,openright]{scrbook}
\usepackage[a4paper,left=2.5cm,right=2.5cm,top=3cm,bottom=3cm,
            bindingoffset=0cm,includefoot=false,twoside]{geometry}
\usepackage[dvipsnames]{xcolor}
\usepackage[pdftex]{graphicx}
\usepackage{titletoc}
\usepackage{hyperref}
\hypersetup{plainpages=false, colorlinks=true,citecolor=blue!80, linkcolor=black, filecolor=red, urlcolor=violet,
pdfpagemode=FullScreen,pdfborder={0 0 0}, breaklinks=true,  bookmarksnumbered=true, bookmarksopen=true}
\usepackage{lipsum}
\usepackage{scrlayer-scrpage}
\usepackage{xhfill}
\usepackage[sfdefault]{universalis}
\usepackage{tikz}
\usetikzlibrary{decorations, decorations.pathmorphing, decorations.pathreplacing}
\definecolor{maincolor}{cmyk}{1, .50, .10, .01}
%% Define some format spacing---------------------------------------------------------
\setlength{\parindent}{1em}\selectfont
\setlength{\parskip}{1em}\selectfont
\renewcommand{\baselinestretch}{1.25}\selectfont
%% Title format for Chapters -------------------------------------------------------
\newcommand{\ssfont}{\fontfamily{bch}\selectfont}
\newcommand{\thesischapterfont}{\color{maincolor}\normalfont\huge\ssfont}
\newcommand{\thesissectionfont}{\color{maincolor}\normalfont\Large\ssfont}
\newcommand{\thesissubsectionfont}{\color{maincolor}\normalfont\large\ssfont}
\newcommand{\fontfootertext}{\color{blue}\normalfont\footnotesize}
\newcommand{\fontfooterpagenumber}{\color{red}\normalfont\normalsize\bfseries}
% headings
\setkomafont{chapter}{\thesischapterfont}
\setkomafont{section}{\thesissectionfont}
\setkomafont{subsection}{\thesissubsectionfont}

%% Header and Footer ---------------------------------------------------------------------- \automark[section]{chapter} \setlength{\headheight}{19pt} \setlength{\footheight}{160pt} \setlength{\footskip}{185pt} \KOMAoption{footwidth}{foot:53pt} \setkomafont{pagefoot}{\fontfootertext} \setkomafont{pagenumber}{\fontfooterpagenumber}

%% command to print the TOC --------------------------------------------- \titlecontents{chapter}[0pc]{\addvspace{1pc}} {\begin{tikzpicture}[remember picture, overlay] \draw[fill=maincolor!90,draw=maincolor!90,rounded corners=5pt] (-2.8,-.2) rectangle (1,.7) node[align=center,font=\color{white}\large\scshape\bfseries, xshift=-1.8cm,yshift=-0.5cm]{Chapter\ \thecontentslabel}; \end{tikzpicture}\hspace{1.5cm}\color{maincolor!90}\large\scshape\bfseries} {\hspace{1.5cm}\color{maincolor!90}\large\scshape\bfseries} {\color{maincolor!90};\dotfill\quad\large\scshape\bfseries\thecontentspage}[\addvspace{0pc}] %***************************************************** \titlecontents{section}[2.4pc]{\addvspace{0pc}} {\hspace{1.6cm}\contentslabel[\thecontentslabel]{2.4pc}}{} {;\dotfill;\normalsize \thecontentspage} [\addvspace{-0.5pc}] %***************************************************** \titlecontents{subsection}[5pc]{\addvspace{0pc}} {\hspace{1.6cm}\contentslabel[\thecontentslabel]{2.4pc}}{} {;\dotfill;\normalsize\thecontentspage} [\addvspace{-0.5pc}] %***************************************************** \makeatletter \renewcommand{\tableofcontents}{ \chapter{ \vspace{-1cm} \begin{tikzpicture}[remember picture, overlay] % Output the chapter image \clip (current page.north west) rectangle ([yshift=-8cm]current page.north east); \node[anchor=north west,inner sep=0pt] at (current page.north west) {\includegraphics[width=\paperwidth]{example-image-a}}; % Box with the chapter title \draw[anchor=west] (current page.north west) node [ anchor=north west, xshift=3cm, yshift=-3.5cm, line width=2pt, rounded corners=10pt, draw=maincolor, fill=black!5, fill opacity=0.1, text opacity=1, inner ysep=12.5pt, inner xsep=20pt, align=flush left, text width=1.2\linewidth, font=\Huge\sffamily\scshape\bfseries\color{maincolor}] { \contentsname }; \end{tikzpicture}} @starttoc{toc}} \makeatother

% Begin document --------------------------------------------- \begin{document} \frontmatter \pagenumbering{roman} \pagestyle{empty}
\setcounter{tocdepth}{2} \tableofcontents
\cleardoublepage \mainmatter \pagenumbering{arabic} \setcounter{page}{1} \pagestyle{headings} % Chapter 1 ----------------------------------- \chapter{Introduction} \lipsum[1-3] \section{Section 1} \lipsum[1-5] \subsection{Subsection 1} \lipsum[1-3] \subsection{Subsection 2} \lipsum[1-3] \section{Section 2} \lipsum[1-3] % Chapter 2 ----------------------------------- \chapter{Control Strategies for Wave Energy Converters: State-of-the-Art} \lipsum[1-3] \section{Section 1} \lipsum[1-5] \subsection{Subsection 1} \lipsum[1-3] \subsection{Subsection 2} \lipsum[1-3] \section{Section 2} \lipsum[1-3] % Chapter 3 ----------------------------------- \chapter{Optimal Control for Wave Energy Converters: Contributions} \section{Manuscript 2: Model Predictive Control for Wave Energy Converters: A Moving Window Blocking Approach} \lipsum[1-3] \section{Section 1} \lipsum[1-3] \section{Section 2} \lipsum[1-3]

\section{Manuscript 2: Efficiency-aware nonlinear model-predictive control with real-time iteration scheme for wave energy converters}
    \lipsum[1-3]
    \section{Section 1}
    \lipsum[1-3]
    \section{Section 2}
    \lipsum[1-3]

\section{Manuscript 3: Nonlinear Model Predictive Control based on Real-Time Iteration Scheme for Wave Energy Converters using WEC-Sim}
    \lipsum[1-3]
    \section{Section 1}
    \lipsum[1-3]
    \section{Section 2}
    \lipsum[1-3]

\end{document}

Edited version: I tried @Jasper proposal, but still with no avail: using the "normal" \chapter{Control Strategies for Wave Energy Converters: State-of-the-Art} and \chapter{Optimal Control for Wave Energy Converters: Contributions}

enter image description here

  • Set the left margin of the ToC entry for chapter to 1.5 cm generally (\titlecontents{chapter}[1.5cm]...) and shift the tikzpicture 1.5 cm to the left. This way, multiple lines will align properly and there is no need for manual line breaks any more. – Jasper Habicht Jul 30 '22 at 09:56

2 Answers2

2

Try this code for ToC chapter definition:

\titlecontents{chapter}[2.4pc]{\addvspace{1pc}}
{%
\begin{tikzpicture}[remember picture, overlay,box/.style = {text width=3cm, font=\color{white}\large\scshape\bfseries}]
    \node (rect) at (-2.5,1ex) [box, draw,thick,minimum width=4cm,minimum height=1cm, fill=maincolor!90,draw=maincolor!90,rounded corners=5pt,align=right ] {Chapter\ \thecontentslabel};       
\end{tikzpicture}   
\hspace*{-1ex}\color{maincolor!90}\large\scshape\bfseries}{}
{\color{maincolor!90}\large\scshape\bfseries\;\dotfill\thecontentspage}
[\addvspace{0pc}]

b

Simon Dispa
  • 39,141
1

Here is a suggestion without package titletoc. KOMA-Script class scrbook loads package tocbasic automatically. So it can be used to format the TOC-entries and the TOC head.

\documentclass[twoside,12pt,openright]{scrbook}
\usepackage[
  hmargin=2.5cm,vmargin=3cm,
  footskip=185pt,includefoot=false
  ]{geometry}
\usepackage{lipsum}
\usepackage{scrlayer-scrpage}
\usepackage{xhfill}
\usepackage[sfdefault]{universalis}
\PassOptionsToPackage{xcolor}{dvipsnames}
\usepackage{tikz}% loads xcolor,graphicx etc.
\usepackage{hyperref}% load after other packages
\hypersetup{
  plainpages=false,
  colorlinks=true, citecolor=blue!80, linkcolor=black, filecolor=red, urlcolor=violet,
  pdfpagemode=FullScreen,pdfborder={0 0 0},
  breaklinks=true,
  bookmarksnumbered=true, bookmarksopen=true
}

\usetikzlibrary{decorations, decorations.pathmorphing, decorations.pathreplacing} \definecolor{maincolor}{cmyk}{1, .50, .10, .01} %% Define some format spacing--------------------------------------------------------- \setparsizes{1em}{1em plus .1\baselineskip}{0pt plus 1fil}% do not change \parindent and \parskip manuelly \renewcommand{\baselinestretch}{1.25}\selectfont %% Title format for Chapters ------------------------------------------------------- \newcommand{\ssfont}{\fontfamily{bch}\selectfont} \newcommand{\thesischapterfont}{\color{maincolor}\normalfont\huge\ssfont} \newcommand{\thesissectionfont}{\color{maincolor}\normalfont\Large\ssfont} \newcommand{\thesissubsectionfont}{\color{maincolor}\normalfont\large\ssfont} \newcommand{\fontfootertext}{\color{blue}\normalfont\footnotesize} \newcommand{\fontfooterpagenumber}{\color{red}\normalfont\normalsize\bfseries} % headings \setkomafont{chapter}{\thesischapterfont} \setkomafont{section}{\thesissectionfont} \setkomafont{subsection}{\thesissubsectionfont}

%% Header and Footer ---------------------------------------------------------------------- \automark[section]{chapter} \setlength{\headheight}{19pt} \setlength{\footheight}{160pt} \setlength{\footskip}{185pt} \KOMAoption{footwidth}{foot:53pt} \setkomafont{pagefoot}{\fontfootertext} \setkomafont{pagenumber}{\fontfooterpagenumber}

%% command to print the TOC --------------------------------------------- \addtokomafont{chapterentry}{\large} \addtokomafont{chapterentrydots}{\color{maincolor!90}} \addtokomafont{chapterentrypagenumber}{\color{maincolor!90}}

\newcommand{\chapterentryformat}[1]{% \begin{tikzpicture}[remember picture, overlay] \draw[fill=maincolor!90,draw=maincolor!90,rounded corners=5pt] (-2.8,-.2) rectangle (1,.7) node[align=center,font=\color{white}\large\bfseries, xshift=-1.8cm,yshift=-0.5cm] {\chaptername\ #1}; \end{tikzpicture}% }

\DeclareTOCStyleEntry[ entrynumberformat=\chapterentryformat, numwidth=1.75cm, raggedentrytext=true, linefill=\usekomafont{chapterentrydots}{\TOCLineLeaderFill} ]{tocline}{chapter} \DeclareTOCStyleEntries[dynindent]{tocline}{section,subsection}

\makeatletter \renewcommand{@dotsep}{2.5}% adjust the space between the filler dots, default is 4.5 \makeatother

\deftocheading{toc}{% \cleardoublepage \begin{tikzpicture}[remember picture, overlay] % Output the chapter image \clip (current page.north west) rectangle ([yshift=-8cm]current page.north east); \node[anchor=north west,inner sep=0pt] at (current page.north west) {\includegraphics[width=\paperwidth]{example-image-a}}; % Box with the chapter title \draw[anchor=west] (current page.north west) node [ anchor=north west, xshift=3cm, yshift=-3.5cm, line width=2pt, rounded corners=10pt, draw=maincolor, fill=black!5, fill opacity=0.1, text opacity=1, inner ysep=12.5pt, inner xsep=20pt, align=flush left, text width=1.2\linewidth, font=\Huge\sffamily\bfseries\color{maincolor}] { \contentsname }; \end{tikzpicture}% \vspace{5cm}\par }

\setcounter{tocdepth}{2}

\begin{document} \frontmatter \pagestyle{empty} \tableofcontents

\mainmatter \pagestyle{headings}% headings is an alias of scrheadings (because of package scrlayer-scrpage)

\chapter{Introduction} \lipsum[1-3] \section{Section 1} \lipsum[1-5] \subsection{Subsection 1} \lipsum[1-3] \subsection{Subsection 2} \lipsum[1-3] \section{Section 2} \lipsum[1-3]

\chapter{Control Strategies for Wave Energy Converters: State-of-the-Art} \lipsum[1-3] \section{Section 1} \lipsum[1-5] \subsection{Subsection 1} \lipsum[1-3] \subsection{Subsection 2} \lipsum[1-3] \section{Section 2} \lipsum[1-3]

\chapter{Optimal Control for Wave Energy Converters: Contributions} \section{Manuscript 2: Model Predictive Control for Wave Energy Converters: A Moving Window Blocking Approach} \lipsum[1-3] \section{Section 1} \lipsum[1-3] \section{Section 2} \lipsum[1-3] \section{Manuscript 2: Efficiency-aware nonlinear model-predictive control with real-time iteration scheme for wave energy converters} \lipsum[1-3] \section{Section 1} \lipsum[1-3] \section{Section 2} \lipsum[1-3] \section{Manuscript 3: Nonlinear Model Predictive Control based on Real-Time Iteration Scheme for Wave Energy Converters using WEC-Sim} \lipsum[1-3] \section{Section 1} \lipsum[1-3] \section{Section 2} \lipsum[1-3] \end{document}

enter image description here

Or if you remove option raggedentrytext=true from the settings for chapter entries:

enter image description here


If you need a manuell line break in TOC, you can use

\documentclass[...,headings=optiontoheadandtoc]{scrbook}

and

\chapter
  [tocentry={\texorpdfstring{Optimal Control for Wave Energy Converters:\\ Contributions}{Optimal Control for Wave Energy Converters: Contributions}}]
  {Optimal Control for Wave Energy Converters: Contributions}

Then the line break is affects only the TOC entry.

Example:

\documentclass[twoside,12pt,openright,headings=optiontoheadandtoc]{scrbook}
\usepackage[
  hmargin=2.5cm,vmargin=3cm,
  footskip=185pt,includefoot=false
  ]{geometry}
\usepackage{lipsum}
\usepackage{scrlayer-scrpage}
\usepackage{xhfill}
\usepackage[sfdefault]{universalis}
\PassOptionsToPackage{xcolor}{dvipsnames}
\usepackage{tikz}% loads xcolor,graphicx etc.
\usepackage{hyperref}% load after other packages
\hypersetup{
  plainpages=false,
  colorlinks=true, citecolor=blue!80, linkcolor=black, filecolor=red, urlcolor=violet,
  pdfpagemode=FullScreen,pdfborder={0 0 0},
  breaklinks=true,
  bookmarksnumbered=true, bookmarksopen=true
}

\usetikzlibrary{decorations, decorations.pathmorphing, decorations.pathreplacing} \definecolor{maincolor}{cmyk}{1, .50, .10, .01} %% Define some format spacing--------------------------------------------------------- \setparsizes{1em}{1em plus .1\baselineskip}{0pt plus 1fil}% do not change \parindent and \parskip manuelly \renewcommand{\baselinestretch}{1.25}\selectfont %% Title format for Chapters ------------------------------------------------------- \newcommand{\ssfont}{\fontfamily{bch}\selectfont} \newcommand{\thesischapterfont}{\color{maincolor}\normalfont\huge\ssfont} \newcommand{\thesissectionfont}{\color{maincolor}\normalfont\Large\ssfont} \newcommand{\thesissubsectionfont}{\color{maincolor}\normalfont\large\ssfont} \newcommand{\fontfootertext}{\color{blue}\normalfont\footnotesize} \newcommand{\fontfooterpagenumber}{\color{red}\normalfont\normalsize\bfseries} % headings \setkomafont{chapter}{\thesischapterfont} \setkomafont{section}{\thesissectionfont} \setkomafont{subsection}{\thesissubsectionfont}

%% Header and Footer ---------------------------------------------------------------------- \automark[section]{chapter} \setlength{\headheight}{19pt} \setlength{\footheight}{160pt} \setlength{\footskip}{185pt} \KOMAoption{footwidth}{foot:53pt} \setkomafont{pagefoot}{\fontfootertext} \setkomafont{pagenumber}{\fontfooterpagenumber}

%% command to print the TOC --------------------------------------------- \addtokomafont{chapterentry}{\large} \addtokomafont{chapterentrydots}{\color{maincolor!90}} \addtokomafont{chapterentrypagenumber}{\color{maincolor!90}}

\newcommand{\chapterentryformat}[1]{% \begin{tikzpicture}[remember picture, overlay] \draw[fill=maincolor!90,draw=maincolor!90,rounded corners=5pt] (-2.8,-.2) rectangle (1,.7) node[align=center,font=\color{white}\large\bfseries, xshift=-1.8cm,yshift=-0.5cm] {\chaptername\ #1}; \end{tikzpicture}% }

\DeclareTOCStyleEntry[ entrynumberformat=\chapterentryformat, numwidth=1.75cm, raggedentrytext=true, linefill=\usekomafont{chapterentrydots}{\TOCLineLeaderFill} ]{tocline}{chapter} \DeclareTOCStyleEntries[dynindent]{tocline}{section,subsection}

\makeatletter \renewcommand{@dotsep}{2.5}% adjust the space between the filler dots, default is 4.5 \makeatother

\deftocheading{toc}{% \cleardoublepage \begin{tikzpicture}[remember picture, overlay] % Output the chapter image \clip (current page.north west) rectangle ([yshift=-8cm]current page.north east); \node[anchor=north west,inner sep=0pt] at (current page.north west) {\includegraphics[width=\paperwidth]{example-image-a}}; % Box with the chapter title \draw[anchor=west] (current page.north west) node [ anchor=north west, xshift=3cm, yshift=-3.5cm, line width=2pt, rounded corners=10pt, draw=maincolor, fill=black!5, fill opacity=0.1, text opacity=1, inner ysep=12.5pt, inner xsep=20pt, align=flush left, text width=1.2\linewidth, font=\Huge\sffamily\bfseries\color{maincolor}] { \contentsname }; \end{tikzpicture}% \vspace{5cm}\par }

\setcounter{tocdepth}{2}

\begin{document} \frontmatter \pagestyle{empty} \tableofcontents

\mainmatter \pagestyle{headings}% headings is an alias of scrheadings (because of package scrlayer-scrpage)

\chapter{Introduction} \lipsum[1-3] \section{Section 1} \lipsum[1-5] \subsection{Subsection 1} \lipsum[1-3] \subsection{Subsection 2} \lipsum[1-3] \section{Section 2} \lipsum[1-3]

\chapter{Control Strategies for Wave Energy Converters: State-of-the-Art} \lipsum[1-3] \section{Section 1} \lipsum[1-5] \subsection{Subsection 1} \lipsum[1-3] \subsection{Subsection 2} \lipsum[1-3] \section{Section 2} \lipsum[1-3]

\chapter [tocentry={\texorpdfstring{Optimal Control for Wave Energy Converters:\ Contributions}{Optimal Control for Wave Energy Converters: Contributions}}] {Optimal Control for Wave Energy Converters: Contributions} \section{Manuscript 2: Model Predictive Control for Wave Energy Converters: A Moving Window Blocking Approach} \lipsum[1-3] \section{Section 1} \lipsum[1-3] \section{Section 2} \lipsum[1-3] \section{Manuscript 2: Efficiency-aware nonlinear model-predictive control with real-time iteration scheme for wave energy converters} \lipsum[1-3] \section{Section 1} \lipsum[1-3] \section{Section 2} \lipsum[1-3] \section{Manuscript 3: Nonlinear Model Predictive Control based on Real-Time Iteration Scheme for Wave Energy Converters using WEC-Sim} \lipsum[1-3] \section{Section 1} \lipsum[1-3] \section{Section 2} \lipsum[1-3] \end{document}

enter image description here

enter image description here

esdd
  • 85,675