I'm trying to customize my TOC as in this post (second example) and I'm having two issues.
The first one is documented but I can't figure out what I'm doing wrong : I want to write "Appendix" instead of "Chapter". If I don't customize \titlecontents{chapter} then everything works fine, but if I do, I get a "Chapter" instead of "Appendix". I've tried all sorts of configs (I think it's due to the book class), with/without \begin{appendices}, loading (or not) the appendix package with the titletoc options... Any help would be very appreciated !
The second "problem" I'm having is I'm trying to customize the look of the subsections in the TOC according to the chapter they're in. Each chapter has its own color and I would like the sections to have the same color as the chapter they're in.
Here is my MWE and the result.
\documentclass[11pt]{book}
\usepackage[table]{xcolor}
\usepackage{ifthen}
\usepackage{tikz,pgf}
\definecolor{chapa}{HTML}{15CA7F}
\definecolor{chapb}{HTML}{CA16BD}
\definecolor{chapc}{HTML}{DE1841}
\makeatletter
\newcommand{\ch@p}{chapa}
\newcommand{\ch@ngeCouleurs}[1]
{
\ifthenelse{\equal{#1}{1}}{\renewcommand{\ch@p}{chapa}}{}
\ifthenelse{\equal{#1}{2}}{\renewcommand{\ch@p}{chapb}}{}
\ifthenelse{\equal{#1}{3}}{\renewcommand{\ch@p}{chapc}}{}
}
\usepackage[titletoc]{appendix}
\usepackage{titletoc}
\usepackage{titlesec}
\contentsmargin{-1.5cm}
\titlecontents{chapter}[4pc]
{\addvspace{30pt}%
\ch@ngeCouleurs{\thecontentslabel}%
\begin{tikzpicture}[remember picture, overlay]%
\draw[\ch@p,fill=\ch@p] (-4.2,-.1) rectangle (-.8,.5);%
\pgftext[left,x=-3.7cm,y=0.2cm]{\color{white}\large\bfseries\sc\@chapapp\ \thecontentslabel};%
\end{tikzpicture}%
\large\bfseries\color{\ch@p!80!black}}%
{}
{}
{\titlerule\, Page \thecontentspage
\begin{tikzpicture}[remember picture, overlay]
\draw[\ch@p] (2pt,0) rectangle (6,0.1pt);
\end{tikzpicture}%
}
[\addvspace{.2cm}]%
\titlecontents{section}[0pc]
{\addvspace{5pt}}
{
\color{\ch@p}\contentslabel[\thecontentslabel]{2pc}\color{black}}
{}
{\hfill\small\color{black}\thecontentspage}
[\addvspace{3pt}]
\makeatother
\begin{document}
\tableofcontents
\chapter{One chapter}
\section{First section}
\section{First subsection}
\chapter{Another chapter}
\section{Foo}
\section{Bar}
\begin{appendices}
\chapter{First appendix}
\end{appendices}
\end{document}
The result (2.1 and 2.2 should be in purple, and "Chapter A" should be "Appendix A").
I think I know how to work around the coloring problem of the appendix (comes from the fact that the chapter counter has been reset which can be avoided using packages totcount and assoccnt).
But I don't understand why my \ch@ngeCouleurs macro has no effect on the \titlecontents{section}. If I could access the chapter number in the \titlecontents{section}, that would solve my problem.
Thank you for reading my (long) post ! And thanks to anyone who can provide help !


\ch@pisn't redefined globally --\renewcommandis not global (unless done in global level) – Jun 12 '16 at 11:32assoccnthere (I am the author ofassoccnt, by the way -- and switch toxassoccntplease;-) – Jun 12 '16 at 11:40Propositionboxes? – Jun 12 '16 at 12:43