# Alignment problem of multiline title in ToC while maintaining the same spacing between title number and title

I have some multiline titles and I want to align the second line with the first line of them. Besides, I use the following code to keep the spacing between title number and title consistent.

\makeatletter
\renewcommand{\numberline}[1]{%
\settowidth\@tempdimb{#1\hspace{0.8em}}%
\ifdim\@tempdima<\@tempdimb%
\@tempdima=\@tempdimb%
\fi%
\hb@xt@\@tempdima{\@cftbsnum #1\@cftasnum\hfil}\@cftasnumb}
\makeatother


I know I can change the value of cftsecnumwidth to control the indentation of the second line. But the problem is that I need different indentation for entries which has different length of title number.

Reminded by comment, I try to use \section[<short title>]{<title>} with parbox to align the <short title> in ToC. However, because I use the [t] parameter to align the title number with the first line of title box, so the page number will also be aligned with the first line instead of the second line, which is the case when I don't use parbox.

This is original complete code.

\documentclass[11pt]{article}

\usepackage{tocloft}

\makeatletter
\renewcommand{\numberline}[1]{%
\settowidth\@tempdimb{#1\hspace{0.8em}}%
\ifdim\@tempdima<\@tempdimb%
\@tempdima=\@tempdimb%
\fi%
\hb@xt@\@tempdima{\@cftbsnum #1\@cftasnum\hfil}\@cftasnumb}
\makeatother

\begin{document}

\tableofcontents
\newpage

\renewcommand\thesection{\S\arabic{section}}
\section{Hello World Hello World Hello World Hello World Hello World Hello World}

\setcounter{section}{10}
\section{Hello World Hello World Hello World Hello World Hello World Hello World}

\renewcommand\thesection{Appendix \Alph{section}}
\section{Hello World Hello World Hello World Hello World Hello World Hello World}

\end{document}


And this is the original result.

I have been troubled by this problem for a few days. If you can give me some suggestions, I will be very grateful.

• ...you should be able to do \section[{\parbox{.}[t]{..}}]{<title>}... – Werner Mar 2 at 17:13
• @Werner Thanks for your help. There is only one small error in your method, which is that [t] parameter should be put before the width parameter. However, new problem arises---the page number will be aligned with the first line instead of the second line， which is the case when I don't use parbox. – Myron Mar 3 at 8:46