4

My question is similar to following one: Table of Contents: Nice Titles for Parts

However, the solution didn't help me enough to resolve my problem.

My question is: In the Table Of Content, I have a title holding on two line, and I need to have the second line of my title indented of .25inch from the first line.

The definition of \l@part in the TOC definition of the package I use is the following:

\newcommand\l@part[2]{%
\ifnum \c@tocdepth >-2\relax
\addpenalty{-\@highpenalty}%
\addvspace{2.25em \@plus\p@}%
\begingroup
  \setlength\@tempdima{3em}%
  \parindent \z@ \rightskip \@pnumwidth
  \parfillskip -\@pnumwidth
  {\leavevmode
   \bfseries #1\hfil \hbox to\@pnumwidth{\hss #2}}\par
   \nobreak
     \global\@nobreaktrue
     \everypar{\global\@nobreakfalse\everypar{}}
\endgroup
\fi}

I tried to add the following before \nobreak:

\advance\leftskip\@tempdima% NEW: comment out if no indentation required for lines 2,3,...

I'm sure that I'm missing a small thing to make everything work, but I can't figure it out. Also, I don't think this solution would work since I need to specify the space of .25''.

The solution given seems to only indent the second line as much as the first line. So I added \hspace{.25in} after \leftskip but it didn't work neither.

Thank you.

1

Gonzalo's answer modified.

\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\hangindent0.25in\hangafter1    %% here changed
      \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}

enter image description here

I have added \hangindent0.25in\hangafter1 at the appropriate place.

| improve this answer | |
  • This doesn't work for me. I tried to add this command at different places with 5in but it doesn't make any difference. My definition is a bit different than the one from Gonzalo, so could it be overwrite by something else? – user1527152 May 14 '15 at 15:34
  • @user1527152 Replace your definition of \l@part with the one in the answer. – user11232 May 14 '15 at 15:41
  • Already tried it break everything. – user1527152 May 14 '15 at 15:48
  • I just replace the part after \leavemode and made some modification and now it work – user1527152 May 14 '15 at 19:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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