8

First post and certainly a tyro at LaTeX. Thanks to all those who have made this site such a helpful resource.

I'm using the memoir class to typeset a novel, and would like to have the Table of Contents page numbers appear ragged right, each page number set a fixed horizontal distance from the end of each chapter title, regardless of chapter title length. I would like to be able to try different spacings to find the most pleasing horizontal gap between the end of chapter title lines and the page numbers.

Any solutions or pointers greatly appreciated.

9

Change the family of commands \cftXleader \cftXafterpnum as shown below:

\documentclass{memoir}

\renewcommand{\cftchapterleader}{}
\renewcommand{\cftchapterafterpnum}{\cftparfillskip}
\renewcommand{\cftsectionleader}{}
\renewcommand{\cftsectionafterpnum}{\cftparfillskip}

\begin{document}

\tableofcontents
\chapter{Test Chapter}
\section{Test Section}

\end{document}

enter image description here

To control the distance you could define auxiliary lengths to be used as the box width used by \cftXformatpnum to format the page number:

\documentclass{memoir}

\newlength\chaplength
\newlength\seclength
\setlength\chaplength{7em}
\setlength\seclength{2em}

\renewcommand{\cftchapterleader}{}
\renewcommand{\cftchapterafterpnum}{\cftparfillskip}
\renewcommand*{\cftchapterformatpnum}[1]{%
  \hbox to \chaplength{\hfill{\cftchapterpagefont #1}}}

\renewcommand{\cftsectionleader}{}
\renewcommand{\cftsectionafterpnum}{\cftparfillskip}
\renewcommand*{\cftsectionformatpnum}[1]{%
  \hbox to \seclength{\hfill{\cftsectionpagefont #1}}}

\begin{document}

\tableofcontents
\chapter{Test Chapter}
\section{Test Section}

\end{document}

enter image description here

| improve this answer | |

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.