0

I have a problem with my ToC chapter titles similar to one posted a long while back about part titles. I'm looking for guidance on how to apply these changes to chapter titles. I'm working with the university's style files, so using tocloft is not practical at this point.

Here's the code example for creating consistent indents for long part titles:

\documentclass{book}
\makeatletter
\def\@part[#1]#2{%
\ifnum \c@secnumdepth >-2\relax
  \refstepcounter{part}%
  \addcontentsline{toc}{part}{\protect\numberline{\thepart}#1}%NEW
\else
  \addcontentsline{toc}{part}{#1}%
\fi
\markboth{}{}%
{\centering
 \interlinepenalty \@M
 \normalfont
 \ifnum \c@secnumdepth >-2\relax
   \huge\bfseries \partname\nobreakspace\thepart
   \par
   \vskip 20\p@
 \fi
 \Huge \bfseries #2\par}%
\@endpart}
\renewcommand*\l@part[2]{%
  \ifnum \c@tocdepth >\m@ne
    \addpenalty{-\@highpenalty}%
    \vskip 1.0em \@plus\p@
    \setlength\@tempdima{3.3em}%NEW: indentation for lines 2,3,... change according to your needs
    \begingroup
       \parindent \z@ \rightskip \@pnumwidth
       \parfillskip -\@pnumwidth
       \leavevmode\large\bfseries
       \advance\leftskip\@tempdima% NEW: comment out if no indentation required for lines 2,3,...
       \hskip -\leftskip
       #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
       \penalty\@highpenalty
  \endgroup
\fi}\makeatother

\begin{document}
\tableofcontents

\part{Test part one with a really really long title spanning two lines}
\part{Test part two with a really really long title spanning two lines}
\part{Test part three with a really really long title spanning two lines}
\part{Test part four with a really really long title spanning two lines}

\end{document}

Output looks like this

enter image description here

3
  • Welcome to TeX.sx!
    – Corentin
    Apr 26, 2013 at 17:33
  • I think I don't quite understand the question; do you want the chapter entries in the ToC to follow the format that part entries have with the code you posted? I mean will part and chapter entries be formatted in the same way? Apr 26, 2013 at 17:36
  • My problem is that when the chapter title in ToC breaks into two lines, the two lines are not equally indented. In the output above, you see that "Test part..." is equally indented with "ning two lines". I'm trying to apply this solution to chapter titles so they also have consistent indentation. Hope that makes sense.
    – dunstantom
    Apr 26, 2013 at 18:09

1 Answer 1

1

So, what I did: copy your \renewcommand*\l@part…, replace \l@part by \l@chapter and remove the \large that I found in this command. So now it looks like:

\documentclass{book}
\makeatletter
\def\@part[#1]#2{%
\ifnum \c@secnumdepth >-2\relax
  \refstepcounter{part}%
  \addcontentsline{toc}{part}{\protect\numberline{\thepart}#1}%NEW
\else
  \addcontentsline{toc}{part}{#1}%
\fi
\markboth{}{}%
{\centering
 \interlinepenalty \@M
 \normalfont
 \ifnum \c@secnumdepth >-2\relax
   \huge\bfseries \partname\nobreakspace\thepart
   \par
   \vskip 20\p@
 \fi
 \Huge \bfseries #2\par}%
\@endpart}
\renewcommand*\l@part[2]{%
  \ifnum \c@tocdepth >\m@ne
    \addpenalty{-\@highpenalty}%
    \vskip 1.0em \@plus\p@
    \setlength\@tempdima{3.3em}%NEW: indentation for lines 2,3,... change according to your needs
    \begingroup
       \parindent \z@ \rightskip \@pnumwidth
       \parfillskip -\@pnumwidth
       \leavevmode\large\bfseries
       \advance\leftskip\@tempdima% NEW: comment out if no indentation required for lines 2,3,...
       \hskip -\leftskip
       #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
       \penalty\@highpenalty
  \endgroup
\fi}

\renewcommand*\l@chapter[2]{%
  \ifnum \c@tocdepth >\m@ne
    \addpenalty{-\@highpenalty}%
    \vskip 1.0em \@plus\p@
    \setlength\@tempdima{3.3em}%NEW: indentation for lines 2,3,... change according to your needs
    \begingroup
       \parindent \z@ \rightskip \@pnumwidth
       \parfillskip -\@pnumwidth
       \leavevmode\bfseries
       \advance\leftskip\@tempdima% NEW: comment out if no indentation required for lines 2,3,...
       \hskip -\leftskip
       #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
       \penalty\@highpenalty
  \endgroup
\fi}\makeatother

\begin{document}
\tableofcontents

\part{Test part one with a really really long title spanning two lines}
\chapter{Test part one with a really really long title spanning two lines}
\chapter{Test part two with a really really long title spanning two lines}
\part{Test part two with a really really long title spanning two lines}
\part{Test part three with a really really long title spanning two lines}
\part{Test part four with a really really long title spanning two lines}

\end{document}

enter image description here

EDIT: The chapter titles should probably read "Test chapter two …" instead of "Test part two …" but you get what I mean.

You must log in to answer this question.

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