4

I would like to use a customize table of contents like this one: How to customize the table of contents using TikZ? (see the "edit 2") but instead of using the book class, I want to use memoir. Unfortunately, everything works fine with the book class but when I try to create my file with the memoir class I have this error:

! Use of \reserved@a doesn't match its definition. \def \reserved@a { \def \@currenvir {tikzpicture}\edef \@currenvli...

I tried to locate the part of the code causing this without success. Any help would be appreciated.

Edit :

the code:

\documentclass{memoir}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{kpfonts}
\usepackage[tmargin=2cm,rmargin=3.8cm,lmargin=3.8cm,bmargin=2cm]{geometry}
\usepackage{tikz}
\definecolor{doc}{RGB}{0,60,110}
\usepackage{titletoc}
\contentsmargin{0cm}
\titlecontents{chapter}[0pc]
{\addvspace{30pt}%
\begin{tikzpicture}[remember picture, overlay]%
\draw[fill=doc!30,draw=doc!30] (-4,-.1) rectangle (-1,.5);%
\pgftext[left,x=-3.7cm,y=0.2cm]{\color{white}\Large\sc\bfseries chapter\ \thecontentslabel};%
\end{tikzpicture}\color{doc!40}\large\sc\bfseries}%
{}
{}
{\;\titlerule\;\large\sc\bfseries Page \thecontentspage
\begin{tikzpicture}[remember picture, overlay]
\draw[fill=doc!25,draw=doc!20] (2pt,0) rectangle (6,0.1pt);
\end{tikzpicture}}%
\titlecontents{section}[2.4pc]
{\addvspace{1pt}}
{\contentslabel[\thecontentslabel]{2.4pc}}
{}
{\hfill\small \thecontentspage}
[]
\titlecontents*{subsection}[4pc]
{\addvspace{-1pt}\small}
{}
{}
{\ --- \small\thecontentspage}
[ \textbullet\ ][]

\makeatletter
\renewcommand{\tableofcontents}{%
    \chapter*{%
\vspace*{-20\p@}%
\begin{tikzpicture}[remember picture, overlay]%
\pgftext[right,x=15cm,y=0.2cm]{\color{doc!30}\Huge\sc\bfseries \contentsname};%
\draw[fill=doc!30,draw=doc!30] (13,-.75) rectangle (20,1);%
\clip (13,-.75) rectangle (20,1);
\pgftext[right,x=15cm,y=0.2cm]{\color{white}\Huge\sc\bfseries \contentsname};%
\end{tikzpicture}}%
\@starttoc{toc}}
\makeatother
\begin{document}
\tableofcontents
\chapter{Questions of Design}
\section{(title section 1)}
\subsection{(title sub-section 1)}
\subsection{(title sub-section 2)}
\section{(title section 2)}
\subsection{(title sub-section 1)}
\subsection{(title sub-section 2)}
\chapter{Questions of Drawing}
\section{(title section 1)}
\subsection{(title sub-section 1)}
\subsection{(title sub-section 2)}
\section{(title section 2)}
\subsection{(title sub-section 1)}
\subsection{(title sub-section 2)}
\chapter{Questions of Technique}
\section{(title section 1)}
\subsection{(title sub-section 1)}
\subsection{(title sub-section 2)}
\section{(title section 2)}
\subsection{(title sub-section 1)}
\subsection{(title sub-section 2)}
\end{document} 
3
  • Welcome to TeX.SX! Please add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}.
    – Holene
    Commented Nov 10, 2013 at 14:56
  • 1
    titlesec and memoir aren't really compatible, see About memoir and titlesec incompatibility
    – egreg
    Commented Nov 10, 2013 at 16:36
  • Thank you Holene, I modified my post according to your remark. Thank you for your input @egreg! After reading of the link you posted, shall I abandon the code I posted or is it a way to adapt it to the memoir class? Maybe using some native memoir possibilities or another package than titlesec?
    – Lorias
    Commented Nov 10, 2013 at 19:46

1 Answer 1

3

The following code compiles:

all \sc to \scshape

the tikzpicture code used inside a \chapter* protected against expansion

and the finishing touch with a redefinition of \chapternumberline

This being said, you could have a look at package etoc for ultimate possibilities of TOC customization, using TikZ if you like.

\documentclass{memoir}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{kpfonts}
\usepackage[tmargin=2cm,rmargin=3.8cm,lmargin=3.8cm,bmargin=2cm]{geometry}
\usepackage{tikz}
\definecolor{doc}{RGB}{0,60,110}
\usepackage{titletoc}
\contentsmargin{0cm}
\titlecontents{chapter}[0pc]
{\addvspace{30pt}%
\begin{tikzpicture}[remember picture, overlay]%
\draw[fill=doc!30,draw=doc!30] (-4,-.1) rectangle (-1,.5);%
\pgftext[left,x=-3.7cm,y=0.2cm]{\color{white}\Large\scshape\bfseries chapter\ \thecontentslabel};%
\end{tikzpicture}\color{doc!40}\large\scshape\bfseries}%
{}
{}
{\;\titlerule\;\large\scshape\bfseries Page \thecontentspage
\begin{tikzpicture}[remember picture, overlay]
\draw[fill=doc!25,draw=doc!20] (2pt,0) rectangle (6,0.1pt);
\end{tikzpicture}}%
\titlecontents{section}[2.4pc]
{\addvspace{1pt}}
{\contentslabel[\thecontentslabel]{2.4pc}}
{}
{\hfill\small \thecontentspage}
[]
\titlecontents*{subsection}[4pc]
{\addvspace{-1pt}\small}
{}
{}
{\ --- \small\thecontentspage}
[ \textbullet\ ][]

\makeatletter
\renewcommand{\tableofcontents}{\def\chapternumberline ##1{##1 }%
    \chapter*{%
\unexpanded{\vspace*{-20\p@}%
\begin{tikzpicture}[remember picture, overlay]%
\pgftext[right,x=15cm,y=0.2cm]{\color{doc!30}\Huge\scshape\bfseries \contentsname};%
\draw[fill=doc!30,draw=doc!30] (13,-.75) rectangle (20,1);%
\clip (13,-.75) rectangle (20,1);
\pgftext[right,x=15cm,y=0.2cm]{\color{white}\Huge\scshape\bfseries \contentsname};%
\end{tikzpicture}}}%
\@starttoc{toc}}
\makeatother
\begin{document}
\tableofcontents
\chapter{Questions of Design}
\section{(title section 1)}
\subsection{(title sub-section 1)}
\subsection{(title sub-section 2)}
\section{(title section 2)}
\subsection{(title sub-section 1)}
\subsection{(title sub-section 2)}
\chapter{Questions of Drawing}
\section{(title section 1)}
\subsection{(title sub-section 1)}
\subsection{(title sub-section 2)}
\section{(title section 2)}
\subsection{(title sub-section 1)}
\subsection{(title sub-section 2)}
\chapter{Questions of Technique}
\section{(title section 1)}
\subsection{(title sub-section 1)}
\subsection{(title sub-section 2)}
\section{(title section 2)}
\subsection{(title sub-section 1)}
\subsection{(title sub-section 2)}
\end{document} 
2
  • Thanks a lot ! Still, I have an issue about the content label for the chapters (\thecontentslabel). It does not appear where it meant to be. The thing is, if I put another label as \thecontentspage it will work as intended. The contents label seems to not be "recognized". As a test I tried to add this line: \pgftext[left,x=-3.5cm,y=-0.2cm]{ TEST \thecontentslabel};% beneath this one: \pgftext[left,x=-3.7cm,y=0.2cm]{\color{white}\Large\scshape\bfseries chapter\ \thecontentslabel};% But only "TEST" appears. Any clue ?
    – Lorias
    Commented Nov 11, 2013 at 12:16
  • @Lorias sorry I am familiar neither with memoir nor with titletoc...
    – user4686
    Commented Nov 11, 2013 at 16:03

You must log in to answer this question.

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