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.

I've designed a whole new fancy chapter header layout, and have hard coded the word "Chapter" in there before the chapter number. I just realized now that this won't work because I have an appendix named "Chapter A".

Is there a variable that will contain the word Chapter or Appendix depending on which it is typesetting at the moment? \chaptername only seems to have the word "Chapter" even though I'm using it under the appendix section.

Edit: I've got it working in my chapter headers, thanks to answers below; but my TOC isn't working properly. I've changed my TOC with titletoc, and it still says "Chapter" even though I've got the following code:

\documentclass{book}
\usepackage{titletoc}
\usepackage{color}

\makeatletter
\titlecontents{chapter}[-2em]
    {\color{cyan}\bfseries\LARGE\addvspace{3mm}}
    {\@chapapp \contentslabel{-0.25em}\hspace{2em}}
    {}
    {\hspace{3em}\contentspage}
\makeatother

\begin{document}
    \tableofcontents
    \chapter{test}
    \appendix
    \chapter{asdf}
\end{document}
share|improve this question
2  
Unfortunately it's called \@chapapp so you need \makeatletter and \makeatother when using it. –  egreg Jan 31 '13 at 21:23

2 Answers 2

up vote 5 down vote accepted

In the standard classes book and report, the \chapter command uses the internal command \@chapapp to typeset chapter headings. \@chapapp is initially defined as \chaptername ("Chapter"), and redefined to \appendixname ("Appendix") as soon as you issue \appendix in the document body.

In response to your follow-up question: Here's one (possibly not the most elegant) way to achieve correct naming in the ToC:

\documentclass{book}
\usepackage{titletoc}
\usepackage{color}

\makeatletter

\titlecontents{chapter}[-2em]
    {\color{cyan}\bfseries\LARGE\addvspace{3mm}}
    {\@chapapp \contentslabel{-0.25em}\hspace{2em}}
    {}
    {\hspace{3em}\contentspage}

\g@addto@macro{\appendix}{%
  \addtocontents{toc}{\protect\renewcommand*{\protect\@chapapp}{\protect\appendixname}}%
}

\makeatother

\begin{document}
    \tableofcontents
    \chapter{test}
    \appendix
    \chapter{asdf}
\end{document}
share|improve this answer
    
\@chapapp indeed works for my custom header. Thanks. But how can I get it to show in my TOC as well? I've modified the TOC with titletoc and even though I've surrounded my code with \makeatletter and \makeatother, it still says "Chapter". –  agent154 Jan 31 '13 at 21:33
    
Do you know how I could redefine \appendix to have \switchchapapp get fired in that? I'd like to make this work without having to get another user to use esoteric commands. –  agent154 Jan 31 '13 at 22:47
    
@agent154 My bad -- answer improved. –  lockstep Jan 31 '13 at 23:26
    
That works beautifully. Thanks. –  agent154 Jan 31 '13 at 23:36

If you use titlesec, then the command you look for is \chaptertitlename that defaults to \chaptername, but it is \appendixname in the appendix.

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.