[Tex/LaTex] Table of Content, indentation within long title

indentationtable of contents

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.

Best Answer

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.

Related Question