[Tex/LaTex] Page number before Chapter title in the Table of Contents with memoir

memoirtable of contents

I've seen in some novel that, in the table of contents, the page number is before the chapter title, for example:

3    Down the Rabbit Hole
7    The Pool of Tears
15   The Caucus Race and a Long Tale

How can I obtain the same using memoir class?

Best Answer

You can achieve the desired result in many ways. Below there's one such possibility; I assumed the sectional unit used was \chapter:

\documentclass{memoir}

% redefinition for the ToC title
\renewcommand\printtoctitle[1]{\HUGE\sffamily#1}

% redefinitions for chapter entries
\renewcommand\chapternumberline[1]{}
\renewcommand\cftchapterfont{\sffamily}
\renewcommand\cftchapterpagefont{\huge\sffamily}

\makeatletter
\newcommand\l@mychap[3]{%
  \vskip2ex%
  \par\noindent
  \parbox{2.5em}{%
    \hfill{\cftchapterpagefont#2}%
  }\hspace*{3em}%
  \parbox{\dimexpr\textwidth-5.5em-15pt\relax}{%
    \cftchapterfont#1%
  }\par%
}

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

\begin{document}

\tableofcontents*

\chapter{Down the Rabbit Hole}
\chapter{The Pool of Tears}
\chapter{The Caucus Race and a Long Tale}
\setcounter{page}{14}% just for the example

\end{document}

enter image description here

The code above will align the page numbers to the right; to get them aligned to the left, \l@mychap must be defined using something like

\newcommand\l@mychap[3]{%
  \vskip2ex%
  \par\noindent
  \parbox{4.5em}{%
    {\cftchapterpagefont#2}\hfill%
  }%
  \parbox{\dimexpr\textwidth-4.5em-15pt\relax}{%
    \cftchapterfont#1%
  }\par%
}

Using this redefinition (in the full example code above) instead of the initial one, one obtains

enter image description here