0

In the table of content, I want to have Appendix A instead of chapter A, Appendix B instead of chapter B, and show on. I can't show this when I use \include{appendix}. Following is my code:

\documentclass{report}
\usepackage{tocloft,calc}
\renewcommand\cftchapaftersnum{}% adds dot after chapter title in ToC
\renewcommand\cftchapdotsep{\cftdotsep}% adds leader dots from chapter titles to page numbers
% chapter and chapter number rather than just number
\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
\cleardoublepage
\addcontentsline{toc}{chapter}{List of Tables}
\listoftables 
\include{chp1}
\include{chp2}
\appendix
\include{appendix} : 
\end{document}

%chp1.txt is 
\chapter{Introduction1}
%chp2.txt is 
\chapter{Introduction2}

%appendix.txt is 

% Appendix A
\chapter{}
\section{hello1}
In the ...
\section{hello2 }

 % Appendix B
\clearpage
\newpage
\chapter{}

\section{bello1}
\section{bello2 }

%table of content output

Contents
    List of Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . .2
    Chapter 1 Introduction1 . . . . . . . . . . . . . . . . . . . . . . . 3
    Chapter 2 Introduction2 . . . . . . . . . . . . . . . . . . . . . . . 4
    Chapter A . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  .5
    A.1 hello1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  5
    A.2 hello2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5
    Chapter B . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
    B.1 bello1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  6
    B.2 bello2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  6

P.S. I am NOT looking for the solution with \input{appendix} for \include{appendix}. I already tried that; although it works for this example, it does not solve my real problem.

Desired table of content output:

Contents
List of Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . .2
Chapter 1 Introduction1 . . . . . . . . . . . . . . . . . . . . . . . 3
Chapter 2 Introduction2 . . . . . . . . . . . . . . . . . . . . . . . 4
Appendix A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5
A.1 hello1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  5
A.2 hello2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5
Appendix B . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6
B.1 bello1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  6
B.2 bello2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  6
  • Please see my answer to a similar question. – Bernard Feb 14 '16 at 23:28
  • Thanks. But with report class, I didn't get that output. – Metrics Feb 14 '16 at 23:59
  • I'd say it's because you load tocloft which must have some interaction with my code. Anyway, your code gives you what you want, or do I miss something? – Bernard Feb 15 '16 at 0:14
  • 1
    I'll try to think about the problem tomorrow. – Bernard Feb 15 '16 at 2:21
  • 1
    I certainly didn't expect it, but adding the other includes caused the problem. Anyway, putting \appendix into the appendix.tex file fixes it. You may have to add it to every appendix file. – John Kormylo Feb 15 '16 at 5:10
2

Moving the \appendix command from the main file to appendix.tex is one of many ways to fix the problem. (Reproducing the problem is the hard part) Having multiple \appendix commands doesn't harm anything except resetting the chapter counter each time.

Everything else is the same except for appendix.tex:

\appendix
% Appendix A
\chapter{}
\section{hello1}
In the ...
\section{hello2 }

 % Appendix B
\clearpage
\newpage
\chapter{}

\section{bello1}
\section{bello2 }

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.