# \chaptername is used even for appendix chapters in ToC

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?

-

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
\protect\renewcommand{\protect\cftchappresnum}{\appendixname\space}%
}%
}
\makeatother
\begin{document}
\tableofcontents
\setcounter{chapter}{500}
\chapter{Hello}
\appendix
\chapter{Hello again}
\end{document}


-
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