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 have searched for something to resolve a problem that has shown up here: How do I get \chaptername to appear in the table of contents?

I have tried the code from that thread. But I got an issue, that is, it adds the \chaptername even for appendix chapters:

Chapter 1. aaaaa
....
Chapter Appendix A

How can I resolve it?

share|improve this question
add comment

1 Answer

up vote 9 down vote accepted

At the start of the appendix, a redefinition of \cftchappresnum must be forwarded to the .toc file. I have appended the definition of \appendix to do so.

\documentclass{book}
\usepackage{tocloft,calc}
\renewcommand{\cftchappresnum}{\chaptername\space}
\setlength{\cftchapnumwidth}{\widthof{\textbf{Appendix~999~}}}
\makeatletter
\g@addto@macro\appendix{%
  \addtocontents{toc}{%
    \protect\renewcommand{\protect\cftchappresnum}{\appendixname\space}%
  }%
}
\makeatother
\begin{document}
\tableofcontents
\setcounter{chapter}{500}
\chapter{Hello}
\appendix
\chapter{Hello again}
\end{document}

enter image description here

share|improve this answer
    
Thanks for you reply! I dont know why, but it's seem that the problem is not complete resolved yet. It doesn't make effect on the first appendix chapter. And the result is: > Chapter A Appendix tittle. > Appendix B Appendix tittle. –  xuansamdinh May 21 '12 at 21:44
    
@xuansamdinh Thanks for accepting my answer, but please also upvote it (this has to be done separately from accepting). –  lockstep May 21 '12 at 21:55
    
Oh, it's suprise that it's doesn't effect to the first chapter when use \include to include appendix chapters, such as \include{appendA}. But when put these chapters directly to the main file or using the \input command, it's work nice! Could you improve the code for more nice working? Thank you! –  xuansamdinh May 21 '12 at 21:58
    
@xuansamdinh Try to add \addtocontents{toc}{\protect\renewcommand{\protect\cftchappresnum}{\appendixnam‌​e\space}} at the start of your first "included" appendix chapter file. I suspect that it's a problem similar to the one solved in tex.stackexchange.com/a/50037/510. –  lockstep May 21 '12 at 22:04
add comment

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.