I use a book class and here is a part of my fancy title page for the mainmatter chapters.

{\tikz[remember picture,overlay]{
\node[fill=nicedarkblue,font=\sffamily\fontsize{96}{72}\bf\selectfont\color{white},anchor=north east, minimum width=3cm, minimum height=3.4cm] 
at ([xshift=-1cm,yshift=-1cm]current page.north east) 
(numb) {\thechapter};
\node[rotate=90,anchor=south,inner sep=4pt,font=\Huge\sffamily] at (numb.west) {Chapter};

I do not master conditions in latex, but I would like to have four different styles:

  • chapter in frontmatter
  • chapter in mainmatter
  • appendix in mainmatter
  • chapter in backmatter

How to branch on these conditions ?

  • I would include a new \titleformat wherever I want a new title format to start... The \titleformat should act like a switch (similar to a font changing macro like \bfseries or \itshape), changing formatting from that point onward; so there's technically no "conditioning" required. A bigger question though: Why do you want to switch formats and not keep things consistent?
    – Werner
    Apr 5, 2014 at 6:27
  • @How do I define other formats with \titleformat? For the bigger question, in fact I want to keep the same "global idea" but I want to change things like the "Chapter" word and the color of the node.
    – Vincent
    Apr 5, 2014 at 6:36
  • You could have a look on the titlesec package (the documentation contains some examples) or using the KOMA classes in order to change the titleformat.
    – user31729
    Apr 5, 2014 at 6:52
  • What do you mean by saying "appendix in mainmatter"? There is a \appendix switch to be used to create appendecies. Shouldn't your third requirement be "chapter in appendix"?
    – Ruben
    Apr 5, 2014 at 8:32

1 Answer 1


Generally speaking, rather than including "conditionals" in the title format to work out where in the document the title is used, you either (a) include macros in the format itself which will expand appropriately (e.g. \chaptertitlename which will be redefined once \appendix is given) or (b) redefine with a new \titleformat at the appropriate point in the document.

Since you didn't give a complete compilable MWE I'm guessing somewhat about your settings. But here's a short example. This is basically your code, but (a) instead of "hardcoding" the word "Chapter" in the bit that prints the colored box, I've used \chaptertitlename and (b) instead of hard-coding a color in the two places you used it, I put a macro which can therefore easily be redefined.


{\tikz[remember picture,overlay]
  {\node[fill=\chaptercolor,%<--- Not hardcoded color
       font=\sffamily\fontsize{96}{72}\bf\selectfont\color{white},anchor=north east, 
       minimum width=3cm, 
       minimum height=3.4cm] 
       at ([xshift=-1cm,yshift=-1cm]current page.north east) 
         (numb) {\thechapter};
           inner sep=4pt,
       at (numb.west) {\chaptertitlename};%<-- Not hardcoded "CHAPTER"
  {\Huge\bfseries\color{\chaptercolor}#1}%< Not hardcoded color








\chapter{Appendix Something}


chapter in red appendix in green

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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