Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
Welcome to TeX.sx! You don't have to sign with your name since it automatically appears in the lower right corner of your post. –  Werner Apr 23 '12 at 21:34

1 Answer 1

up vote 8 down vote accepted

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.