Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
    
Welcome to TeX.sx! –  Corentin Apr 26 '13 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? –  Gonzalo Medina Apr 26 '13 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 '13 at 18:09

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.