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.

2 Answers2

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.

  • 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. –  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
1

I had the same problem. What I did is

\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

% i started changing from here

\leavevmode % removed the opening brace \bfseries \advance\leftskip@tempdima % added this line \hskip -\leftskip % added this line too #1\hfil \hbox to@pnumwidth{\hss #2}\par % removed the closing brace \nobreak \global@nobreaktrue \everypar{\global@nobreakfalse\everypar{}} \endgroup \fi}

try this. I don't know what was the problem. I got some ideas from here: Meaning of "\advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip"