# Align section number with bottom line of title in TOC with tocloft

I have a customized TOC modified with tocloft that I am vary pleased with (see below). The problem is when I have chapter titles that are more than one line long. The large chapter numbers are then aligned with the first line. I would like it to be aligned with the second (or potentially third) bottom line of the chapter title, and when the "appendix" line is added for appendices.

One way to achieve this would be to place the chapter title in a parbox that is bottom aligned. The problem here is that the chapter title is not explicit (i.e. as #1) in tocloft so I don't know how to include it as an argument. Another alternative would be to have it a minipage that is bottom aligned. One could then redefine \cftchapaftersnumb to include \begin{minipage}. But where do I place the end of the environment?

Note that a solution need to account for \cftchapaftersnumb{\textsc{appendix}\par} in the appendix. (Is \\ better than \par here?)

\documentclass{book}
\usepackage{tocloft}
\usepackage{color}
\usepackage{etoolbox}
\usepackage[toc]{multitoc}

\def\marked{red}

\setlength\cftchapnumwidth{2.5em}

\renewcommand\cftchapleader{\hspace{1.5em plus 1fil}} % Ensure space between title and pagenumber.
\renewcommand\cftchappresnum{\upshape\liningfont\bfseries\LARGE\color{\marked}}
\renewcommand\cftchapafterpnum{\smallskip\nobreak}

\renewcommand\cftchapfont{\itshape\bfseries}
\renewcommand\cftchappagefont{\itshape\bfseries}

\def\protect\cftchapfont{\normalfont}
\def\protect\cftchappagefont{\normalfont}
\protect\setlength\cftbeforechapskip{\smallskipamount}
}}
\def\protect\cftchapfont{\itshape\bfseries}
\def\protect\cftchappagefont{\itshape\bfseries}
\protect\setlength\cftbeforechapskip{\bigskipamount}
}}
\preto\appendix{
}

\begin{document}

\tableofcontents

\chapter{Some chapter}
\chapter{Some chapter}
\chapter{Some chapter with long name}
\chapter{Some chapter}
\chapter{Some chapter}
\chapter{Some chapter}
\chapter{Some chapter}
\chapter{Some chapter}
\chapter{Some chapter}
\chapter{Some chapter}
\chapter{Some chapter}

\appendix
\chapter{Some appendix}
\chapter{Some appendix}
\end{document}


You can patch \chapter. Direct attempt with etoolbox failed for a reason I had no time to investigate, thus I just copied over the definition from book.cls and customized it. The .66\columnwidth is empirical, you will probably know better than me from tocloft doc what to say exactly.

Edit: I am not sure about what you want with \appendix (as in comment to the earlier answer) but perhaps this is it.

\documentclass{book}
\usepackage{tocloft}
\usepackage{color}
\usepackage{etoolbox}
\usepackage[toc]{multitoc}

\DeclareRobustCommand*\AppTocLine {}

\makeatletter
\def\@chapter[#1]#2{\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
\refstepcounter{chapter}%
\typeout{\@chapapp\space\thechapter.}%
{\protect\numberline{\thechapter}\protect\parbox[b]{.66\columnwidth}{\AppTocLine #1}}%
\else
\fi
\else
\fi
\chaptermark{#1}%
\if@twocolumn
\else
\fi}
\makeatother

\def\marked{red}

\setlength\cftchapnumwidth{2.5em}

\renewcommand\cftchapleader{\hspace{1.5em plus 1fil}} % Ensure space between title and pagenumber.
%\renewcommand\cftchappresnum{\upshape\liningfont\bfseries\LARGE\color{\marked}}
% \liningfont ?
\renewcommand\cftchappresnum{\upshape\bfseries\LARGE\color{\marked}}
\renewcommand\cftchapafterpnum{\smallskip\nobreak}

\renewcommand\cftchapfont{\itshape\bfseries}
\renewcommand\cftchappagefont{\itshape\bfseries}

\def\protect\cftchapfont{\normalfont}
\def\protect\cftchappagefont{\normalfont}
\protect\setlength\cftbeforechapskip{\smallskipamount}
}}
\def\protect\cftchapfont{\itshape\bfseries}
\def\protect\cftchappagefont{\itshape\bfseries}
\protect\setlength\cftbeforechapskip{\bigskipamount}
}}
\preto\appendix{
}

\begin{document}

\tableofcontents

\chapter{Some chapter}
\chapter{Some chapter}
\chapter{Some chapter with long name}
\chapter{Some chapter}
\chapter{Some chapter}
\chapter{Some chapter}
\chapter{Some chapter}
\chapter{Some chapter}
\chapter{Some chapter}
\chapter{Some chapter}
\chapter{Some chapter}

\appendix
\chapter{Some appendix}
\chapter{Some appendix}
\end{document}


\documentclass{book}
\usepackage{tocloft}
\usepackage{color}
\usepackage{etoolbox}
\usepackage[toc]{multitoc}

\makeatletter
\def\@chapter[#1]#2{\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
\refstepcounter{chapter}%
\typeout{\@chapapp\space\thechapter.}%
{\protect\numberline{\thechapter}\protect\parbox[b]{.66\columnwidth}{#1}}%
\else
\fi
\else
\fi
\chaptermark{#1}%
\if@twocolumn
\else
\fi}
\makeatother

\def\marked{red}

\setlength\cftchapnumwidth{2.5em}

\renewcommand\cftchapleader{\hspace{1.5em plus 1fil}} % Ensure space between title and pagenumber.
%\renewcommand\cftchappresnum{\upshape\liningfont\bfseries\LARGE\color{\marked}}
% \liningfont ?
\renewcommand\cftchappresnum{\upshape\bfseries\LARGE\color{\marked}}
\renewcommand\cftchapafterpnum{\smallskip\nobreak}

\renewcommand\cftchapfont{\itshape\bfseries}
\renewcommand\cftchappagefont{\itshape\bfseries}

\def\protect\cftchapfont{\normalfont}
\def\protect\cftchappagefont{\normalfont}
\protect\setlength\cftbeforechapskip{\smallskipamount}
}}
\def\protect\cftchapfont{\itshape\bfseries}
\def\protect\cftchappagefont{\itshape\bfseries}
\protect\setlength\cftbeforechapskip{\bigskipamount}
}}
\preto\appendix{
}

\begin{document}

\tableofcontents

\chapter{Some chapter}
\chapter{Some chapter}
\chapter{Some chapter with long name}
\chapter{Some chapter}
\chapter{Some chapter}
\chapter{Some chapter}
\chapter{Some chapter}
\chapter{Some chapter}
\chapter{Some chapter}
\chapter{Some chapter}
\chapter{Some chapter}

\appendix
\chapter{Some appendix}
\chapter{Some appendix}
\end{document}


• This works, although I would prefer a way of solving this with tocloft commands. Also I would have to redefine the definition of \chapter a second time for the appendices. I will wait a couple of days before accepting this answer to see if someone comes up with a tocloft solution. Mar 16 '15 at 15:01
• After Edit: That is precisely what I had in mind. Thanks a lot for the help. Mar 17 '15 at 16:25