# Appendix with titletoc and memoir

I'm trying to customize the TOC layout with titletoc in a memoir document.

The chapter styling works well as below, but if I try the appendix section, I'll get an error for missing number.

I think I see that this is because \chapternumberline is renewed to \numberline, and that doesn't take in the A as the appendix number.

But if \chapternumberline isn't renewed this way, it errors out with Undefined control sequence for \@chapapp@head in the memoir definition:

\newcommand{\chapternumberline}[1]{%
\chapternumberlinehook{#1}%
\@cftasnumb}


So it looks like memoir is locking horns with titlesec. Any suggestions to on how to pacify them?

The aim is to have the appendix appear similar to the chapter:

 Chapter 1 * It Came Into My Head         3
Appendix A * The Time Machine             5


(In the MWE below the appendix styling is commented out, otherwise it would be MNWE)

mwe.toc

\contentsline {chapter}{\chapternumberline {1}It Came Into My Head}{3}
\contentsline {appendix}{\chapternumberline {A}The Time Machine}{5}
\contentsfinish


mwe.tex

\documentclass[11pt]{memoir}

\makeatletter

\usepackage{titletoc}

\usepackage{fontspec}
\defaultfontfeatures{Ligatures={TeX}}
\setmainfont{TeX Gyre Pagella}

% Fixes Undefined control sequence error for \@chapapp@head
\renewcommand\chapternumberline[1]{\numberline{#1}}

\titlecontents{chapter}[6pc]
{\normalsize}%
{%
\contentsmargin{0pt}%
\makebox[0pt][r]{%
\chaptername~{\thecontentslabel}%
\hspace*{0.5em}$\cdot$\hspace*{0.5em}%
}%
}
{\contentsmargin{0pt}%
\itshape}
{\hfill\normalsize\thecontentspage}

% FIXME: perhaps \numberline is erroring out b/c "A" is not numerical
%! Missing number, treated as zero.
%                   \ttll@appendix
%l.21 ...rline {A}The Time Machine}{11}{appendix.A}

%\titlecontents{appendix}[6pc]
%{\normalsize}%
%{%
%  \contentsmargin{0pt}%
%  \makebox[0pt][r]{%
%    \appendixname~{\thecontentslabel}%
%    \hspace*{0.5em}$\cdot$\hspace*{0.5em}%
%  }%
%}
%{\contentsmargin{0pt}%
%\itshape}
%{\hfill\normalsize\thecontentspage}

\makeatother

\begin{document}

\tableofcontents*

'In another moment we were standing face to face, I and this fragile thing out of futurity\ldots

\appendix

\chapter{The Time Machine}

'There were others coming, and presently a little group of perhaps eight or ten\ldots

\end{document}


You can \let the command \ttll@appendix to be \ttll@chapter:

\documentclass[11pt]{memoir}
\usepackage{titletoc}
\usepackage{fontspec}
\defaultfontfeatures{Ligatures={TeX}}
%\setmainfont{TeX Gyre Pagella}

% Fixes Undefined control sequence error for \@chapapp@head
\renewcommand\chapternumberline[1]{\numberline{#1}}

\titlecontents{chapter}[6pc]
{\normalsize}%
{%
\contentsmargin{0pt}%
\makebox[0pt][r]{%
\chaptername~{\thecontentslabel}%
\hspace*{0.5em}$\cdot$\hspace*{0.5em}%
}%
}
{\contentsmargin{0pt}%
\itshape}
{\hfill\normalsize\thecontentspage}

\makeatletter
\let\ttll@appendix\ttll@chapter
\titlecontents{appendix}[6pc]
{\normalsize}%
{%
\contentsmargin{0pt}%
\makebox[0pt][r]{%
\appendixname~{\thecontentslabel}%
\hspace*{0.5em}$\cdot$\hspace*{0.5em}%
}%
}
{\contentsmargin{0pt}%
\itshape}
{\hfill\normalsize\thecontentspage}
\makeatother

\begin{document}

\tableofcontents*

'In another moment we were standing face to face, I and this fragile thing out of futurity\ldots

\appendix
\chapter{The Time Machine}

'There were others coming, and presently a little group of perhaps eight or ten\ldots

\end{document}


Instead of using titletoc (which might produce problems if hyperref is going yo be used), you could use the built in mechanisms offered by memoir and inspired in the tocloft package; a little example producing a result similar to the one you want (some details still have to be adjusted):

\documentclass[11pt]{memoir}
\usepackage{fontspec}
\defaultfontfeatures{Ligatures={TeX}}
%\setmainfont{TeX Gyre Pagella}

\newlength\mylen
\renewcommand\cftchapteraftersnum{\hspace{0.5em}$\cdot$\hspace{0.5em}}
\settowidth\mylen{\cftchapterpresnum\cftchapteraftersnum}
\renewcommand\cftchapterfont{\normalfont}
\renewcommand\cftchapterpagefont{\itshape}

\makeatletter
\renewcommand*{\l@chapter}[2]{%
\l@chapapp{\makebox[7em][l]{\hfill\chaptername~}#1}{#2}{\cftchaptername}}
\renewcommand*{\l@appendix}[2]{%
\l@chapapp{\makebox[7em][l]{\hfill\appendixname~}#1}{#2}{\cftappendixname}}
\makeatother

\begin{document}

\tableofcontents*

'In another moment we were standing face to face, I and this fragile thing out of futurity\ldots

\appendix
\chapter{The Time Machine}

'There were others coming, and presently a little group of perhaps eight or ten\ldots

\end{document}


In my example I commented out the line \setmainfont{TeX Gyre Pagella} since I don't have that font.

• Awesome! I thought TeX Gyre Pagella was part of every distribution, but I'll stop using it in my examples then. – Gambhiro Apr 22 '13 at 7:19