5

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?

Gonzalo Medina
  • 505,128
Davide
  • 51
  • 2

1 Answers1

5

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

Gonzalo Medina
  • 505,128
  • How is it possible to extend the left position of number to section pages too? thanx! – user41063 Mar 13 '14 at 23:43
  • @user41063 : You can change the l@chapter like so : \renewcommand*{\l@section}[2]{% \l@mytocentry{\Large#1}{#2}{\sectionname}% } See the MWE of my question here which shows both Chapters and Sections : https://tex.stackexchange.com/questions/547344/add-a-vertical-line-between-chapters-sections-and-page-number-in-toc – agryson Jun 01 '20 at 13:20