I use memoir
class and want to customize the table-of-contents and chapters style. When I use \renewcommand*\l@chapter[2]
I get this error after the second compilation:
Undefined control sequence.
\chapternumberline ... \@tempdima {\@chapapp@head
\@cftbsnum #1\@cftasnum \h...
l.2 ...pter}{\chapternumberline {1}Chapter One}{3}
My code:
\documentclass{memoir}
\usepackage{xcolor}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{titletoc}
\usepackage{etoolbox}
\definecolor{secnum}{RGB}{13,151,225}
\definecolor{ptcbackground}{RGB}{212,237,252}
\definecolor{ptctitle}{RGB}{0,177,235}
\makeatletter
\renewcommand*\l@chapter[2]{%
\ifnum \c@tocdepth >\m@ne
\addpenalty{-\@highpenalty}%
\vskip 2.0em \@plus\p@
\setlength\@tempdima{1.5em}%
\begingroup
\parindent \z@ \rightskip \@pnumwidth
\parfillskip -\@pnumwidth
\leavevmode
\advance\leftskip\@tempdima
\hskip -\leftskip
\colorbox{ptctitle}{\strut%
\makebox[\dimexpr\textwidth-2\fboxsep-7pt\relax][l]{%
\color{white}\bfseries\sffamily#1%
\nobreak\hfill\nobreak\hb@xt@\@pnumwidth{\hss #2}}}\par\smallskip
\penalty\@highpenalty
\endgroup
\fi}
\makeatother
\begin{document}
\tableofcontents
\chapter{Chapter One}
\section{Section One One}
\subsection{Section One Two}
\chapter{Chapter Two}
\section{Section Two One}
\end{document}
In book
class, however, it works with no error!
Best Answer
The definition you have been modifying stems from
book.cls
, so it is clear it works there.memoir.cls
has a completely different way of defining chapters, so you can easily produce a conflict by "injecting" code frombook.cls
there. Document structure etc. are completely in the resposibility of document classes, so you need to consider which class you are using. Please modify the code from memoir.cls instead.Here is a starting point. I tried to be as "minimally invasive" as possible, but I'm really no Memoir expert. From the look of it, it'll need some more fiddling, but the definitions are really quite different: