Text Formatting`Hanging' \part title in ToC

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

`Hanging' \part title in ToC

Post by svend_tveskaeg »

Hi all.

Consider the following MWE:

Code: Select all

\documentclass{article}

\usepackage[colorlinks=true]{hyperref}
\usepackage{hypdvips}

\makeatletter
\def\@part[#1]#2{%
    \ifnum \c@secnumdepth >\m@ne
      \refstepcounter{part}%
      \addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
    \else
      \addcontentsline{toc}{part}{#1}%
    \fi
    {\parindent \z@
     \interlinepenalty \@M
     \normalfont
     \ifnum \c@secnumdepth >\m@ne
       \Large\bfseries\hfil\partname~\thepart\hfil
       \par\nobreak
     \fi
     \huge\bfseries\sffamily\raggedleft #2%
     \markboth{}{}\par}%
    \nobreak
    \vskip 3ex
    \@afterheading}
\makeatother

\begin{document}

\tableofcontents

\part{A long, non-sense title in order to illustrate my point regarding the problem}

\section{A long, non-sense title in order to illustrate my point regarding the problem}

\end{document}
How do I get the second line in the \part header to `hang' as in the \section header?

Furthermore, is it possible to make ``I'' and the space between this number and the title non-interactive? (This is not as important as the other problem. Therefore, if you can only help with the first problem, please post your solution anyway.)

Thank you in advance!

P.S. The two loaded packages (among others) are used in my non-test document.
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

`Hanging' \part title in ToC

Post by svend_tveskaeg »

I have found the following in article.cls:

Code: Select all

\newcommand\@pnumwidth{1.55em}
\newcommand\@tocrmarg{2.55em}
\newcommand\@dotsep{4.5}
\setcounter{tocdepth}{3}
\newcommand\tableofcontents{%
    \section*{\contentsname
        \@mkboth{%
           \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
    \@starttoc{toc}%
    }

\newcommand*\l@section[2]{%
  \ifnum \c@tocdepth >\z@
    \addpenalty\@secpenalty
    \addvspace{1.0em \@plus\p@}%
    \setlength\@tempdima{1.5em}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode \bfseries
      \advance\leftskip\@tempdima
      \hskip -\leftskip
      #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
    \endgroup
  \fi}
I think this sets the section and puts it in the ToC, but I am by no means sure.

Is there any `hang'-like command in there?

I hope this can give a hint towards a solution to someone smarter than me!
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
Post Reply