Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
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

1 Answer 1

up vote 1 down vote accepted

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:

enter image description here

\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).

share|improve this answer
    
That works perfect. Thank you so much! –  agent154 Jan 31 '13 at 3:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.