附錄取代目錄中的章節

附錄取代目錄中的章節

在目錄中,我希望用附錄 A 取代 A 章,用附錄 B 取代 B 章,並繼續顯示。我使用時無法顯示此內容\include{appendix}。以下是我的程式碼:

\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 }

%目錄輸出

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

PS 我不是尋找\input{appendix}for 的解決方案\include{appendix}。我已經嘗試過了;雖然它適用於這個例子,但它並沒有解決我真正的問題。

所需的目錄輸出:

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

答案1

\appendix命令從主文件移至appendix.tex是解決該問題的多種方法之一。 (重現問題是困難的部分)擁有多個命令除了每次\appendix重置計數器之外不會造成任何損害。chapter

除了以下內容之外,其他一切都相同appendix.tex

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

 % Appendix B
\clearpage
\newpage
\chapter{}

\section{bello1}
\section{bello2 }

相關內容