I have yet another (baffling) question. Suppose I have the figure attached enter image description here

The question is how can I move the chapter numbers to align with the first line of the chapter title ? i.e using the figure, I'd like to move 11 to align with chapter 3 and 9 to align with chapter 2.

I appreciate all the help I get from here. Makes me understand faster this business of typesetting with LaTeX. By the way, I use Memoir class.

  • 1
    Interesting question! I guess the desired style is very unusual. I suggest: have a quick look into the TOCs of 10 good books to check if anyone ever typesets the page number above and right of the last word of the title instead of following on the same line. If you are still convinced, we could work it out. Page 3 resp. figure 1 of the tocloft documentation shows a typical TOC entry layout.
    – Stefan Kottwitz
    Commented Mar 2, 2011 at 17:39
  • 2
    One "way" to do this is to make sure your chapter titles are short and don't wrap. :-) You can do this with the optional argument of the \chapter command.
    – Alan Munn
    Commented Mar 2, 2011 at 19:29
  • You can have a look at this answer of Herbert; it should be possible to solve your problem in a similar way (as suggested by daleif). Commented Mar 3, 2011 at 13:08

4 Answers 4


Solution using titletoc

I find that the titletoc package provides the best options for customization — as long as you really know what you want! Here is an implementation for the chapter entry:


% This command "floats" the page number to the far right of the current line.
  \hbox to 0pt{%
  {chapter}                % 1. <section>
  [0pt]                    % 2. <left> indent (none here)
  {}                       % 3. <above code>: i.e. vertical space
  {%                       % 4. <numbered-entry-format> for numbered chapters
  {}                       % 5. <numberledd-entry-format> for unnumbered chapters
  {}                       % 6. <filler-page-format> no filler needed
  [\vspace{\baselineskip}] % 7. <after code>: i.e. vertical space

% I am not exactly sure what I should do here, but \chapternumberline has
% \@chapapp@head which is undefined when I use titletoc... This is an
% unexplained hack to get it working

\chapter{First chapter}
\chapter{Second chapter, in which many wonderful things happen, and then other things.}

titletoc solution


I first define the command \floatcontentspage:

  \hbox to 0pt{%

This is intended to be inserted at the start of a contents line after the left indent (of \leftskip). It typesets its contents in a box of width 0pt so that it does not affect the rest of the line. I first insert some space to total \textwidth - \leftskip - \rightskip to obey the current margins, then set the page number using the \contentspage command which I have wrapped in \textbf{} to match the style of the original poster. This will push the page number out to the right after the inserted space.

I then use the \titlecontents command to define the formatting of the contents line. It takes arguments in the following order:

  1. {chapter} specifies the section type.
  2. [0pt] is the optional left indent (none here: you would probably want this for section etc.).
  3. {} There is no above code (vertical space).
  4. This is the main entry for numbered chapters discussed in a moment.
  5. {} I have not defined anything for unnumbered chapters.
  6. {} There is no filler-page-format since we have already typeset the pagenumber.
  7. [{\vspace{\baselineskip}] I have added some space after the chapter entry. (You might like to do this before instead.)

The work is done by argument 4.:

  {%                       % 4. <numbered-entry-format> for numbered chapters

This calls \contentspush which inserts some text and then indents the remaining lines accordingly. We insert our \floatcontentspage command first which will float the page number to the right but take no space, then we insert the \chaptername and \thecontentlabel (in \textbf{}) which gives "Chapter 1" etc. Finally we insert some space to separate the title from the number.

Finally, I had to redefine \chapternumberline to call \numberline: I do not understand exactly why, but \chapternumberline uses \@chapapp@head which is undefined...

As you can see, the titletoc package allows for great flexibility, but requires that you know exactly what you want, and you generally must define all of your entries (I have only provided the chapter definition here. How do you want the sections defined?) Provided that you have a clear idea, though, it is the best tool in my opinion.


Here's a minimal example that shows the problem, but I don't have a solution yet:

\chapter{First chapter, in which many wonderful things happen. And then other things.}
\chapter{Second chapter, in which many wonderful things happen. And then other things.}

Memoir section 9.2 has the ToC methods given, and says the code for typesetting a numbered chapter is more or less

{\cftchapterfont {\cftchaptername \cftchapterpresnum SNUM\cftchapteraftersnum\hfil} \cftchapteraftersnumb TITLE}

with substitutions made for the chapter number as SNUM, chapter title as TITLE, and the page number as PAGE.

The default definition for \cftchapterformatpnum should be something like

\hbox to \@pnumwidth{\hfil{\cftchapterpagefont #1}}}

but since the page number is limited to a box on the regular baseline, I don't know if there's an easy way of moving up a few lines before typesetting that box.

But maybe this will narrow down the problem enough for someone else to post a solution.


As the desired style is rather unusual, there is no simple solution. You'll have to recode the \l@chapter command placing the title inside a \parbox that is aligned at the top line. Then it should be doable.

  • Nice to have here at tex.sx! I took the freedom to edit your answer to make it a bit clearer, OK? Commented Mar 3, 2011 at 13:04

You still have to rewrite \l@chapapp, using an overlapping box or \rlap. I would not us this, because it is realy ugly :-)


  \ifnum \c@tocdepth >\m@ne
    \vskip \cftbeforechapterskip
    {\memRTLleftskip \cftchapterindent\relax
     \memRTLrightskip \@tocrmarg
     \parfillskip -\memRTLrightskip
     \parindent \cftchapterindent\relax
     \let\@cftbsnum \cftchapterpresnum
     \let\@cftasnum \cftchapteraftersnum
     \let\@cftasnumb \cftchapteraftersnumb
     \advance\memRTLleftskip \@tempdima 
     \makebox[0pt][l]{\makebox[\linewidth-\@tempdima][r]{\myformatpnum{#2}}}%<<<NEW LINE
     \null\nobreak\hskip -\memRTLleftskip
     {\cftchapterfont #1}\nobreak




\chapter{This is the first chapter}
\chapter{This is the second chapter, This is the second chapter, This is the second chapter}
\chapter{This is the third chapter}
\chapter{This is the forth chapter, This is the forth chapter, This is the forth chapter}

\chapter{Appendix one}
  • nice one. I'm actually a but lost here. Where does the indentation in front of the outer make box come from? The leftskip isn't altered until the line after it.
    – daleif
    Commented Mar 3, 2011 at 19:43
  • @daleif Strange indeed. Looks if the box output is delayed until the paragraph is set (including the glues). I have changed the above code by moving the \makebox after the \leftskip setting. This is technically more correct i hope.
    – Danie Els
    Commented Mar 5, 2011 at 4:07
  • I'm tempted to add hooks to be able to do this. I actually have several undocumented hooks in the memoir TOC code, to be able to do interesting things like measuring stuff. I'll document them at some point.
    – daleif
    Commented Mar 6, 2011 at 14:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .