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.

For example - if I use \frontmatter, \mainmatter, \appendix, and \backmatter... can I use titlesec to format the "chapters" differently? I use tikz to style my main chapters and appendix headings, but I want the table of contents and other things in the front to not use the same style, as well as my index at the back.

This is what I'm using right now for my chapter header style.

\documentclass{book}
\usepackage{tikz}
\usepackage[explicit]{titlesec}
\usepackage{geometry}
\geometry{
  left=2.50in,
  right=0.75in,
  top=1.25in,
  bottom=1.25in,
  marginparwidth=1.5in,
  marginparsep=.5in,
  asymmetric}

\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!50] (0,-1) rectangle
            (25cm,3cm);
          \draw[fill=cyan!50] (0,-24) rectangle
            (25cm,-25cm);
          \ifttl@label% <---------------------- Added condition on \ifttl@label
            \node[anchor=west,xshift=.236\paperwidth,yshift=-.01\paperheight,rectangle]
                {\color{white}\LARGE \MakeUppercase{\@chapapp} \Huge\thechapter};
          \fi% <------------------------------- end condition on \ifttl@label
         \end{tikzpicture}
        };
    \end{tikzpicture}\endgraf
    \vskip-.7cm
    \color{cyan}\Huge\raggedright\leftskip-1cm
    \MakeUppercase{#1}\endgraf
    }
\titlespacing*{\chapter}{0pt}{10pt}{0pt}{}
\makeatother
\begin{document}
  \chapter{test}

\end{document}
share|improve this question
    
What does "the other" style look like? –  Werner Feb 23 '13 at 2:02
    
I don't have one defined yet. Was just wondering if it can be arbitrarily changed. But I think I found something anyhow, I'm working on it to see if I can get it to work; It involves using etoolbox to make some conditionals and using \gappto and \gpreto to hook onto \mainmatter and such to toggle them –  agent154 Feb 23 '13 at 2:06
    
Yes, you can either define a generic style or change/switch the style altogether. etoolbox for patching is also good. My request for the other style was merely to have something to play with. –  Werner Feb 23 '13 at 2:09

1 Answer 1

OK, After a bit of poking around, I figured out that I could just hook onto the commands that I wanted to control.

I setup a toggle using etoolbox as such

\newtoggle{fancychapter}

Then I hooked onto the various section commands and toggled it as needed.

\gpreto{\frontmatter}{%
  \togglefalse{fancychapter}}
\gpreto{\mainmatter}{%
  \toggletrue{fancychapter}}
\gpreto{\backmatter}{%
  \togglefalse{fancychapter}}

After this, I added two conditionals to my custom chapter header as follows:

\titleformat{\chapter}
  {\normalfont\sffamily\Huge\scshape}
  {}
  {0pt}
  {
    \thispagestyle{empty}    % Remove page number on new chapters
    \iftoggle{fancychapter}{%
    \begin{tikzpicture}[remember picture,overlay]
      \node[yshift=-3cm] at (current page.north west)
        {\begin{tikzpicture}[remember picture, overlay]
          \draw[fill=cyan!50] (0,-1) rectangle
            (25cm,3cm);
          \draw[fill=cyan!50] (0,-24) rectangle
            (25cm,-25cm);
          \ifttl@label% <---------------------- Added condition on \ifttl@label
            \node[anchor=west,xshift=.236\paperwidth,yshift=-.01\paperheight,rectangle]
                {\color{white}\LARGE \MakeUppercase{\@chapapp} \Huge\thechapter};
          \fi% <------------------------------- end condition on \ifttl@label
         \end{tikzpicture}
        };
    \end{tikzpicture}\endgraf}%
    {\titlespacing*{\chapter}{0pt}{35pt}{0pt}{}}
    \vskip-.7cm
    \color{cyan}\Huge\raggedright\leftskip-1cm
    }

It's not working 100% as of yet, but the idea is there.

share|improve this answer

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.