1

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}

\preto\frontmatter{\addtocontents{toc}{
    \def\protect\cftchapfont{\normalfont}
    \def\protect\cftchappagefont{\normalfont}
    \protect\setlength\cftbeforechapskip{\smallskipamount}
  }}
\preto\mainmatter{\addtocontents{toc}{
  \def\protect\cftchapfont{\itshape\bfseries}
  \def\protect\cftchappagefont{\itshape\bfseries}
   \protect\setlength\cftbeforechapskip{\bigskipamount}
  }}
\preto\appendix{
  \addtocontents{toc}{\def\protect\cftchapfont{\normalfont}}
  \addtocontents{toc}{\def\protect\cftchappagefont{\normalfont}}
  \addtocontents{toc}{\def\protect\cftchapaftersnumb{\textsc{appendix}\par}}
}

\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}

enter image description here

2
+50

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.}%
       \addcontentsline{toc}{chapter}%
       {\protect\numberline{\thechapter}\protect\parbox[b]{.66\columnwidth}{\AppTocLine #1}}%
                       \else
       \addcontentsline{toc}{chapter}{\protect\parbox[b]{.66\columnwidth}{\AppTocLine #1}}%
                       \fi
                    \else
       \addcontentsline{toc}{chapter}{\protect\parbox[b]{.66\columnwidth}{\AppTocLine #1}}%
                    \fi
                    \chaptermark{#1}%
                    \addtocontents{lof}{\protect\addvspace{10\p@}}%
                    \addtocontents{lot}{\protect\addvspace{10\p@}}%
                    \if@twocolumn
                      \@topnewpage[\@makechapterhead{#2}]%
                    \else
                      \@makechapterhead{#2}%
                      \@afterheading
                    \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}

\preto\frontmatter{\addtocontents{toc}{
    \def\protect\cftchapfont{\normalfont}
    \def\protect\cftchappagefont{\normalfont}
    \protect\setlength\cftbeforechapskip{\smallskipamount}
  }}
\preto\mainmatter{\addtocontents{toc}{
  \def\protect\cftchapfont{\itshape\bfseries}
  \def\protect\cftchappagefont{\itshape\bfseries}
   \protect\setlength\cftbeforechapskip{\bigskipamount}
  }}
\preto\appendix{
  \addtocontents{toc}{\def\protect\cftchapfont{\normalfont}}
  \addtocontents{toc}{\def\protect\cftchappagefont{\normalfont}}
%  \addtocontents{toc}{\def\protect\cftchapaftersnumb{\textsc{appendix}\par}}
  \addtocontents{toc}{\def\AppTocLine{\textsc{appendix}\protect\par}}
}

\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}

enter image description here


first answer

\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.}%
       \addcontentsline{toc}{chapter}%
       {\protect\numberline{\thechapter}\protect\parbox[b]{.66\columnwidth}{#1}}%
                       \else
       \addcontentsline{toc}{chapter}{\protect\parbox[b]{.66\columnwidth}{#1}}%
                       \fi
                    \else
       \addcontentsline{toc}{chapter}{\protect\parbox[b]{.66\columnwidth}{#1}}%
                    \fi
                    \chaptermark{#1}%
                    \addtocontents{lof}{\protect\addvspace{10\p@}}%
                    \addtocontents{lot}{\protect\addvspace{10\p@}}%
                    \if@twocolumn
                      \@topnewpage[\@makechapterhead{#2}]%
                    \else
                      \@makechapterhead{#2}%
                      \@afterheading
                    \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}

\preto\frontmatter{\addtocontents{toc}{
    \def\protect\cftchapfont{\normalfont}
    \def\protect\cftchappagefont{\normalfont}
    \protect\setlength\cftbeforechapskip{\smallskipamount}
  }}
\preto\mainmatter{\addtocontents{toc}{
  \def\protect\cftchapfont{\itshape\bfseries}
  \def\protect\cftchappagefont{\itshape\bfseries}
   \protect\setlength\cftbeforechapskip{\bigskipamount}
  }}
\preto\appendix{
  \addtocontents{toc}{\def\protect\cftchapfont{\normalfont}}
  \addtocontents{toc}{\def\protect\cftchappagefont{\normalfont}}
  \addtocontents{toc}{\def\protect\cftchapaftersnumb{\textsc{appendix}\par}}
}

\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}

enter image description here

3
  • 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.
    – Andreas
    Mar 16 '15 at 15:01
  • After Edit: That is precisely what I had in mind. Thanks a lot for the help.
    – Andreas
    Mar 17 '15 at 16:25
  • glad it helped :-)
    – user4686
    Mar 17 '15 at 17:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.