3

I have a problem in the sheet dedicated to the table of contents. I'm using titlesec/titletoc/tikz which works fine except in the page "table of contents".

I have this result :

enter image description here

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 :


enter image description here

Thank you for help.

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

2 Answers 2

6

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}%

\usepackage[colorlinks]{hyperref}


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

\end{document}

This provides:

enter image description here

and

enter image description here

5
  • 1
    This would break in the appendix; \ifnum\value{chapter}=0 should be used.
    – egreg
    Sep 27, 2013 at 12:15
  • Just tested and it's true: it definitely needs the more robust test you pointed out. Sep 27, 2013 at 12:30
  • Also the braces around \thesection and \thesubsection should be removed.
    – egreg
    Sep 27, 2013 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, 2013 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. Sep 27, 2013 at 12:44
4

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.

2
  • 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, 2013 at 12:53
  • 1
    And I didn't find any documentation about \boxedchapter as it is a command you defined. So define also \unnumberedboxedchapter. Sep 27, 2013 at 13:07

You must log in to answer this question.

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