2

I'd like to configure my table of contents as this, into a book document : the page number (in red color) before the chapter title (in black color).

For example:

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

For the configuration of the order, I've seen this answer, which do the job for memoir document but not for book document :

https://tex.stackexchange.com/posts/55669/revisions

The code of this revision :

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

How can I obtain the same result for a latex book document ?

And can I declare a red color just for page number in the toc ?

1

Here is your output under memoir:

enter image description here

Here is the output under book with the suggested minimal example:

enter image description here

\documentclass{book}

\usepackage{tocloft,xcolor}

% redefinition for the ToC title
\renewcommand{\cfttoctitlefont}{\Huge\sffamily}

% redefinitions for chapter entries
\renewcommand{\cftchappresnum}[1]{\makebox[\cftchapnumwidth][r]{%
  \cftchappagefont
  \raisebox{-.2\height}[0pt][0pt]{\color{red}\chappagenum}\quad}}
\renewcommand\cftchapfont{\sffamily}
\renewcommand\cftchappagefont{\huge\sffamily}
\setlength{\cftchapnumwidth}{5.5em}
\setlength{\cftbeforechapskip}{3ex}% Adjust to suit your needs
\cftsetpnumwidth{0pt}% Not really needed...

\makeatletter
\newcommand{\chappagenum}{}
\let\oldl@chapter\l@chapter
\renewcommand{\l@chapter}[2]{%
  \renewcommand{\chappagenum}{#2}%
  \oldl@chapter{#1}{}%
}
\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}

tocloft was used to manipulate the ToC-related entries, as it has a user interface that is very similar to what memoir provides.

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.