# Problem with titlesec/titletoc/tikz

I have this result :

The problem is that I don't want to have this "Chapitre 0 :" before "Table des matières" (i.e. Table of contents).

The code used is :

% |_-_-_-_-_-_-_-_-| Package pour redéfinir les titres |_-_-_-_-_-_-_-_-|%
\usepackage{titlesec}
\usepackage{titletoc}

% |_-_-_-_-_-_-_-_-|  Numérotation des sections  |_-_-_-_-_-_-_-_-|%
\setcounter{secnumdepth}{5}
\renewcommand{\thechapter}{\arabic{chapter}}
\renewcommand{\thesection}{\arabic{section}}
\renewcommand{\thesubsection}{{\thesection}.\alph{subsection}}
\renewcommand{\thesubsubsection}%
{{\thesubsection}$_{\textnormal{\bfseries\emph{\arabic{subsubsection}}}}$}
\renewcommand{\theparagraph}{}
\renewcommand{\thesubparagraph}{}

% >>>> A tikz box for chapters

\newcommand\boxedchapter[1]{{%
\begin{center}
\begin{tikzpicture}
\node (0,0) [left color=Marron!40!white, right     color=Anthracite!20%
, text=RougeSang, font=\bf\Huge] {Chapitre \thechapter : #1} ;
\end{tikzpicture}%
\end{center}
}}
\titleformat{\chapter}%
{}%
{}%
{0pt}%
{\boxedchapter}%


If I remove all the part % >>>> A tikz box for chapters, the problem disappears (there is only "Table des matières" without "Chapitre 0 :"), but "Chapitre 1", "Chapitre 2", etc. disappear too, and I would like to keep this (except for the table of contents), like this :

Thank you for help.

• could put the code section and subsection – Eliezer Jun 26 '15 at 15:50

The problem is quite easy to be solved: it is just needed to check whether the counter \thechapter has values different from 0. Thus:

\newcommand\boxedchapter[1]{{%
\begin{center}
\begin{tikzpicture}
\ifnum\value{chapter}=0% only the content is boxed
\node (0,0) [left color=Marron!40!white, right color=Anthracite!20, text=RougeSang, font=\bf\Huge] {#1} ;
\else% display Chapter <number> : title
\node (0,0) [left color=Marron!40!white, right color=Anthracite!20, text=RougeSang, font=\bf\Huge] {Chapitre \thechapter : #1} ;
\fi
\end{tikzpicture}%
\end{center}
}}


A complete example (with invented colors, as the definitions of Marron, Anthracite and RougeSang are not known):

\documentclass[a4paper,11pt,x11names]{report}

\usepackage[french]{babel}
% |_-_-_-_-_-_-_-_-| Package pour redéfinir les titres |_-_-_-_-_-_-_-_-|%
\usepackage{tikz}
\usepackage{titlesec}
\usepackage{titletoc}

\colorlet{RougeSang}{OrangeRed1}
\colorlet{Marron}{Sienna1}
\colorlet{Anthracite}{LightYellow1}

% |_-_-_-_-_-_-_-_-|  Numérotation des sections  |_-_-_-_-_-_-_-_-|%
\setcounter{secnumdepth}{5}
\renewcommand{\thechapter}{\arabic{chapter}}
\renewcommand{\thesection}{\arabic{section}}
\renewcommand{\thesubsection}{\thesection.\alph{subsection}}
\renewcommand{\thesubsubsection}%
{\thesubsection$_{\textnormal{\bfseries\emph{\arabic{subsubsection}}}}$}
\renewcommand{\theparagraph}{}
\renewcommand{\thesubparagraph}{}

% >>>> A tikz box for chapters

\newcommand\boxedchapter[1]{{%
\begin{center}
\begin{tikzpicture}
\ifnum\value{chapter}=0
\node (0,0) [left color=Marron!40!white, right color=Anthracite!20, text=RougeSang, font=\bf\Huge] {#1} ;
\else
\node (0,0) [left color=Marron!40!white, right color=Anthracite!20, text=RougeSang, font=\bf\Huge] {Chapitre \thechapter : #1} ;
\fi
\end{tikzpicture}%
\end{center}
}}
\titleformat{\chapter}%
{}%
{}%
{0pt}%
{\boxedchapter}%

\begin{document}
\tableofcontents
\chapter{Les vecteurs}
\section{Notion de vecteur}

\end{document}


This provides:

and

• This would break in the appendix; \ifnum\value{chapter}=0 should be used. – egreg Sep 27 '13 at 12:15
• Just tested and it's true: it definitely needs the more robust test you pointed out. – Claudio Fiandrino Sep 27 '13 at 12:30
• Also the braces around \thesection and \thesubsection should be removed. – egreg Sep 27 '13 at 12:34
• Thank you for your answers, it's perfect ... the \ifnum\value{chapter}=0 is working very fine. Sorry for the colors ... I forgot I created colors that are not known. – stan Sep 27 '13 at 12:42
• @stan: no problem, even if it is always better to provide complete minimal working examples so that it is easier to derive a solution. As a new user, I would courteously suggest for the future to upvote all answers you find useful, including those to others' questions and to check/accept the best answers to your own questions by clicking the green tick on the left-hand side of the answer. – Claudio Fiandrino Sep 27 '13 at 12:44

Use the numberless key to define the format for unnumbered chapters. E.g.

\titleformat{name=\chapter,numberless}%
{}%
{}%
{0pt}%
{\unnumberedboxedchapter}%


with a suitable definition of \unnumberedboxedchapter.

• I tried to use your solution, but I didn't succeed ... I didn't find any documentation about {\unnumberedboxedchapter I don't know how to use it. – stan Sep 27 '13 at 12:53
• And I didn't find any documentation about \boxedchapter as it is a command you defined. So define also \unnumberedboxedchapter`. – Ulrike Fischer Sep 27 '13 at 13:07