# How do I hide “Chapter 0” in this custom style when using a numberless chapter?

Everything works perfect when I use \chapter{chaptername}, but I noticed that my table of contents and other similar non-numbered chapters have a "Chapter 0" in my header.

\titleformat{\chapter}
{\normalfont\sffamily\Huge\scshape}
{}{0pt}
{\thispagestyle{empty}    % Remove page number on new chapters
\setcounter{definition}{0} % Reset Definition Counter
\begin{tikzpicture}[remember picture,overlay]
\node[yshift=-3cm] at (current page.north west)
{\begin{tikzpicture}[remember picture, overlay]
\draw[fill=cyan] (0,-1) rectangle
(25cm,3cm);
\draw[fill=cyan] (0,-24) rectangle
(25cm,-25cm);
\node[anchor=west,xshift=.21\paperwidth,yshift=-.01\paperheight,rectangle]
{\color{white}\LARGE CHAPTER \Huge\thechapter};
\node[anchor=west,xshift=.21\paperwidth,yshift=-.065\paperheight,rectangle]
{\color{cyan}\Huge\MakeUppercase{#1}};
\end{tikzpicture}
};
\end{tikzpicture}
}


I looked it up briefly, but I can't seem to make sense of how to use conditionals to determine certain things.

-
Try to put the code inside {\ifnum \c@chapter>\z@ } –  Sigur Jan 31 '13 at 1:30
@Sigur With that, I get errors "Missing number, treated as zero" –  agent154 Jan 31 '13 at 1:40
I believe that you have to use \makeatletter ... \makeatother and put your code inside it since the if contains @. –  Sigur Jan 31 '13 at 1:43
Same problem, sadly. –  agent154 Jan 31 '13 at 1:45
For future reference, rather than submitted code snippets, it's best to provide complete, minimal working examples (MWE) of what you're after. –  Werner Jan 31 '13 at 3:34

titlesec sets \ttl@labelfalse if you call \chapter* (and true otherwise). You can use this to condition on inserting a node containing the chapter heading:

\documentclass{report}
\usepackage[explicit]{titlesec}% http://ctan.org/pkg/titlesec
\usepackage{tikz}% http://ctan.org/pkg/pgf
\makeatletter
\titleformat{\chapter}
{\normalfont\sffamily\Huge\scshape}
{}{0pt}
{\thispagestyle{empty}    % Remove page number on new chapters
\begin{tikzpicture}[remember picture,overlay]
\node[yshift=-3cm] at (current page.north west)
{\begin{tikzpicture}[remember picture, overlay]
\draw[fill=cyan] (0,-1) rectangle
(25cm,3cm);
\draw[fill=cyan] (0,-24) rectangle
(25cm,-25cm);
\ifttl@label% <---------------------- Added condition on \ifttl@label
\node[anchor=west,xshift=.21\paperwidth,yshift=-.01\paperheight,rectangle]
{\color{white}\LARGE CHAPTER \Huge\thechapter};
\fi% <------------------------------- end condition on \ifttl@label
\node[anchor=west,xshift=.21\paperwidth,yshift=-.065\paperheight,rectangle]
{\color{cyan}\Huge\MakeUppercase{#1}};
\end{tikzpicture}
};
\end{tikzpicture}
}
\makeatother
\begin{document}
\tableofcontents
\chapter{A numbered chapter}
\chapter*{An unnumbered chapter}
\end{document}


Note the positioning of \makeatletter and \makeatother (outside the definition of \titleformat).

-
That works perfect. Thank you so much! –  agent154 Jan 31 '13 at 3:37