使用 tocloft 创建新的附录列表

使用 tocloft 创建新的附录列表

我刚刚实施了 Mike Renfro 的解决方案这里,但附录列表中的内容也会列在目录中,但情况不应该如此。如何确保避免这种情况?下面是我使用的代码。report使用类是因为我想在文档中包含章节。

\documentclass[12pt]{report}
\usepackage{lipsum}\usepackage{tocloft}
\newcommand{\listappendixname}{List of Appendices}
\newlistof{appendix}{app}{\listappendixname}
\setcounter{appdepth}{2}
\renewcommand{\theappendix}{\Alph{appendix}}
\renewcommand{\cftappendixpresnum}{Appendix\space}
\setlength{\cftbeforeappendixskip}{\baselineskip}
\setlength{\cftappendixnumwidth}{1in}
\newlistentry[appendix]{subappendix}{app}{1}
\renewcommand{\thesubappendix}{\theappendix.\arabic{subappendix}}
\renewcommand{\cftsubappendixpresnum}{Appendix\space}
\setlength{\cftsubappendixnumwidth}{1in}
\setlength{\cftsubappendixindent}{0em}

\renewcommand{\appendix}[1]{%
  \refstepcounter{appendix}%
  \chapter{\theappendix\space #1}%
  \addcontentsline{app}{appendix}{\protect\numberline{\theappendix}#1}%
  \par
}

\newcommand{\subappendix}[1]{%
  \refstepcounter{subappendix}%
  \section{\thesubappendix\space #1}%sub
  \addcontentsline{app}{subappendix}{\protect\numberline{\thesubappendix}#1}%
}

\usepackage{fmtcount,etoolbox}
\makeatletter
\patchcmd{\@makechapterhead}{\thechapter}{\Numberstring{chapter}}{}{}
\patchcmd{\chaptermark}{\thechapter}{\NUMBERstring{chapter}}{}{}
\makeatother
\newcommand{\thetocchap}{\NUMBERstring{chapter}}

\begin{document}
\tableofcontents
\listofappendix

\chapter{Foo} \lipsum[1]
\section{Bar} \lipsum[2]%sub
\chapter{Additional Foo} \lipsum[3]
\section{Additional Bar} \lipsum[4]%sub

\begin{appendices}

\appendix{Baz} \lipsum[5]
\subappendix{Qux} \lipsum[6]
\appendix{Additional Baz} \lipsum[7]
\subappendix{Additional Qux} \lipsum[8]
\end{appendices}
\end{document}

答案1

\addtocontents{toc}{\protect\setcounter{tocdepth}{-2}}在文档主体中立即添加\begin{appendices}。(并且不要忘记加载appendix包。)

\documentclass[12pt]{report}
\usepackage{lipsum}
\usepackage{tocloft}
\usepackage{appendix}
\newcommand{\listappendixname}{List of Appendices}
\newlistof{appendix}{app}{\listappendixname}
\setcounter{appdepth}{2}
\renewcommand{\theappendix}{\Alph{appendix}}
\renewcommand{\cftappendixpresnum}{Appendix\space}
\setlength{\cftbeforeappendixskip}{\baselineskip}
\setlength{\cftappendixnumwidth}{1in}
\newlistentry[appendix]{subappendix}{app}{1}
\renewcommand{\thesubappendix}{\theappendix.\arabic{subappendix}}
\renewcommand{\cftsubappendixpresnum}{Appendix\space}
\setlength{\cftsubappendixnumwidth}{1in}
\setlength{\cftsubappendixindent}{0em}

\renewcommand{\appendix}[1]{%
  \refstepcounter{appendix}%
  \chapter{\theappendix\space #1}%
  \addcontentsline{app}{appendix}{\protect\numberline{\theappendix}#1}%
  \par
}

\newcommand{\subappendix}[1]{%
  \refstepcounter{subappendix}%
  \section{\thesubappendix\space #1}%sub
  \addcontentsline{app}{subappendix}{\protect\numberline{\thesubappendix}#1}%
}

\usepackage{fmtcount,etoolbox}
\makeatletter
\patchcmd{\@makechapterhead}{\thechapter}{\Numberstring{chapter}}{}{}
\patchcmd{\chaptermark}{\thechapter}{\NUMBERstring{chapter}}{}{}
\makeatother
\newcommand{\thetocchap}{\NUMBERstring{chapter}}

\begin{document}
\tableofcontents
\listofappendix

\chapter{Foo} \lipsum[1]
\section{Bar} \lipsum[2]%sub
\chapter{Additional Foo} \lipsum[3]
\section{Additional Bar} \lipsum[4]%sub

\addtocontents{toc}{\protect\setcounter{tocdepth}{-2}}

\begin{appendices}

\appendix{Baz} \lipsum[5]
\subappendix{Qux} \lipsum[6]
\appendix{Additional Baz} \lipsum[7]
\subappendix{Additional Qux} \lipsum[8]
\end{appendices}
\end{document}

相关内容