8

I would like to have the Table of Contents of the book I am editing showing first the pages of the chapters and then the chapter titles. Something like this book: enter image description here

I am working with XeTeX (through LyX) and my document class is Memoir.

  • Do you want this behaviour just for chapter entries or for all sectional units in the ToC? Which document class are you using? – Gonzalo Medina Jul 26 '13 at 20:59
  • Hello. My ToC is made up of Parts and Chapters, there are no other sections in the book. The document class is Memoir. – Cato Philosophus Jul 26 '13 at 21:01
  • So, just to be sure, this is to apply to parts and chapter entries, or just to chapter entries? – Gonzalo Medina Jul 26 '13 at 21:08
  • Parts and chapters, you are right. – Cato Philosophus Jul 26 '13 at 21:18
6

Here's one possibility (chapter number for unnumbered chpaters have been included before the corresponding titles, as has been requested in a comment):

\documentclass{memoir}
\usepackage{graphicx}
\renewcommand\partnumberline[1]{}
\renewcommand\chapternumberline[1]{#1~\raisebox{.2ex}{\scalebox{0.75}{\textbullet}~}}
\renewcommand\cftpartpagefont{\huge\bfseries}
\renewcommand\cftpartfont{\LARGE\bfseries}
\renewcommand\cftchapterpagefont{\normalfont\large\itshape}
\renewcommand\cftchapterfont{\normalfont}

\newlength\ToCindent
\setlength\ToCindent{4em}

\makeatletter
\renewcommand*{\l@part}[2]{%
  \ifnum \c@tocdepth >-2\relax
    \cftpartbreak
    \begingroup
      {\leftskip0pt\noindent
       \interlinepenalty\@M
       \leavevmode
       \parbox[t]{\ToCindent}{\makebox[2em][r]{\cftpartpagefont #2}\hfill}%
       \parbox[t]{\dimexpr\textwidth-\ToCindent\relax}{\cftpartfont #1}%
       }
      \par\nobreak
        \global\@nobreaktrue
        \everypar{\global\@nobreakfalse\everypar{}}%
    \endgroup
  \fi}

\newcommand*{\l@mychap}[3]{%
  \def\@chapapp{#3}
  \vskip2ex%
  \par%
  \noindent\parbox[t]{\ToCindent}{\makebox[2em][r]{\cftchapterpagefont#2}\hfill}%
  \parbox[t]{\dimexpr\textwidth-\ToCindent\relax}{\cftchapterfont#1}\par%
}

\renewcommand*{\l@chapter}[2]{%
  \l@mychap{#1}{#2}{\chaptername}%
}

\renewcommand*{\l@appendix}[2]{%
  \l@mychap{#1}{#2}{\appendixname}%
}
\makeatother

\begin{document}

\tableofcontents*

\part{A test part}
\chapter{Test chapter with a really long title spanning several lines just for the example}
\chapter{Another test chapter}
\addcontentsline{toc}{chapter}{A test unnumbered chapter}
\chapter{Another test chapter with an interesting title}
\part{Another test part}
\chapter{Test chapter with a really long title spanning several lines just for the example}
\chapter{Another test chapter}
\addcontentsline{toc}{chapter}{Another test unnumbered chapter}
\chapter{Another test chapter with an interesting title}
\part{Yet another test part}
\chapter{Test chapter with a really long title spanning several lines just for the example}
\chapter{Another test chapter}
\chapter{Another test chapter with an interesting title}

\end{document}

enter image description here

I add here another option showing the page number and chapter number separated by a bullet, as was originally required in the comment; I prefer the previous solution since this one might result in confusion:

\documentclass{memoir}
\usepackage{graphicx}

\renewcommand\partnumberline[1]{}
\renewcommand\chapternumberline[1]{\makebox[0pt][l]{%
  \llap{\raisebox{.2ex}{\scalebox{0.75}{\textbullet}}\,#1\hspace{1.2em}}}}
\renewcommand\cftpartpagefont{\huge\bfseries}
\renewcommand\cftpartfont{\LARGE\bfseries}
\renewcommand\cftchapterpagefont{\normalfont}
\renewcommand\cftchapterfont{\normalfont}

\newlength\ToCindent
\setlength\ToCindent{4.5em}

\makeatletter
\renewcommand*{\l@part}[2]{%
  \ifnum \c@tocdepth >-2\relax
    \cftpartbreak
    \begingroup
      {\leftskip0pt\noindent
       \interlinepenalty\@M
       \leavevmode
       \parbox[t]{\ToCindent}{\makebox[2em][r]{\cftpartpagefont #2}\hfill}%
       \parbox[t]{\dimexpr\textwidth-\ToCindent\relax}{\cftpartfont #1}%
       }
      \par\nobreak
        \global\@nobreaktrue
        \everypar{\global\@nobreakfalse\everypar{}}%
    \endgroup
  \fi}

\newcommand*{\l@mychap}[3]{%
  \def\@chapapp{#3}
  \vskip2ex%
  \par%
  \noindent\parbox[t]{\ToCindent}{\makebox[2em][r]{\cftchapterpagefont#2}\hfill}%
  \parbox[t]{\dimexpr\textwidth-\ToCindent\relax}{\cftchapterfont#1}\par%
}

\renewcommand*{\l@chapter}[2]{%
  \l@mychap{#1}{#2}{\chaptername}%
}

\renewcommand*{\l@appendix}[2]{%
  \l@mychap{#1}{#2}{\appendixname}%
}
\makeatother

\begin{document}

\tableofcontents*

\part{A test part}
\chapter{Test chapter with a really long title spanning several lines just for the example}
\chapter{Another test chapter}
\addcontentsline{toc}{chapter}{A test unnumbered chapter}
\chapter{Another test chapter with an interesting title}
\part{Another test part}
\chapter{Test chapter with a really long title spanning several lines just for the example}
\chapter{Another test chapter}
\addcontentsline{toc}{chapter}{Another test unnumbered chapter}
\chapter{Another test chapter with an interesting title}
\part{Yet another test part}
\chapter{Test chapter with a really long title spanning several lines just for the example}
\chapter{Another test chapter}
\chapter{Another test chapter with an interesting title}

\end{document}

enter image description here

The \ToCindent length controls the separation between page numbers and titles.

  • Thank you for the solution! Would be possible to add the chapter number before the chapter title for numbered chapters? Maybe something like a middot (·) might be useful to separate pages from chapter number. – Cato Philosophus Jul 26 '13 at 23:45
  • @CatoPhilosophus please see my updated answer. I included the chapter numbers as part of the entry (and changed the font for chapter page numbers), as I think this is better to avoid confusions with the page numbers. – Gonzalo Medina Jul 26 '13 at 23:58
  • @CatoPhilosophus I added another option to my answer showing the layout you suggested in your comment; I personally find the first option less confusing. – Gonzalo Medina Jul 27 '13 at 1:28
  • Nice solution! I prefer the first solution as well. I wonder if this can be made to work with other classes (like Koma-Script). – Joseph Jul 27 '13 at 12:08

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.