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} 
Lorias
  • 41

1 Answers1

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}

  • 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 Nov 11 '13 at 12:16
  • @Lorias sorry I am familiar neither with memoir nor with titletoc... –  Nov 11 '13 at 16:03