未顯示的數字列表

未顯示的數字列表

每當我使用以下程式碼時

 \appendix
 \addcontentsline{toc}{chapter}{9 \enspace Appendices}
 \addtocontents{toc}{\protect\setcounter{tocdepth}{-1}}

為了避免在目錄中列出各個附錄,圖表列表(lof)消失了。我已檢查從附錄中刪除上述命令,出現 lof。

答案1

您必須tocdepth在附錄之後恢復計數器\addtocontents{toc}{\protect\setcounter{tocdepth}{2}}

\documentclass{report}

\begin{document}
\tableofcontents
\listoffigures

\begin{figure}
  \caption{figure}
\end{figure}

\appendix
\addcontentsline{toc}{chapter}{9 \enspace Appendices}
\addtocontents{toc}{\protect\setcounter{tocdepth}{-1}}
\chapter{Appendix chapter that is not listed in the TOC}
...
%<end of appendix>
\addtocontents{toc}{\protect\setcounter{tocdepth}{2}}
\end{document}

假設附錄是文件的最後部分(這可能是不是是這種情況,所以在這裡要小心)你可以修補文件的末尾,例如

\let\oldenddocument\enddocument
\def\enddocument{%
  \addtocontents{toc}{\protect\setcounter{tocdepth}{2}}
  \oldenddocument}

然後是文件

\documentclass{report}

\makeatletter
\g@addto@macro\appendix{%
  \addcontentsline{toc}{chapter}{9 \enspace Appendices}
  \addtocontents{toc}{\protect\setcounter{tocdepth}{-1}}}
\let\ltx@enddocument\enddocument
\def\enddocument{%
  \addtocontents{toc}{\protect\setcounter{tocdepth}{2}}
  \ltx@enddocument}
\makeatother

\begin{document}
\tableofcontents
\listoffigures

\begin{figure}
  \caption{figure}
\end{figure}

\appendix
\chapter{Appendix chapter that is not listed in the TOC}
\end{document}

將產生與上面相同的結果。請注意,也正在進行修補\appendix以保持文檔正文乾淨:

\g@addto@macro\appendix{%
  \addcontentsline{toc}{chapter}{9 \enspace Appendices}
  \addtocontents{toc}{\protect\setcounter{tocdepth}{-1}}}

無論如何都應該這樣做。最後,如果附錄不是文件的結論部分,人們可能會考慮將附錄包裝到一個環境中,以便有一個結束標記,因此有一個適當的位置可以掛鉤(例如使用指令\def\endappendix{\addtocontents{toc}{\protect\setcounter{tocdepth}{2}}}),然後說

\documentclass{book}

\makeatletter
\g@addto@macro\appendix{%
  \addcontentsline{toc}{chapter}{9 \enspace Appendices}
  \addtocontents{toc}{\protect\setcounter{tocdepth}{-1}}}
\def\endappendix{\addtocontents{toc}{\protect\setcounter{tocdepth}{2}}}
\makeatother

\begin{document}
\tableofcontents
\listoffigures

\begin{figure}
  \caption{figure}
\end{figure}

\begin{appendix}
\chapter{Appendix chapter that is not listed in the TOC}
...
\end{appendix}

\backmatter
\chapter{After the appendix}
\end{document}

需要注意的是,這是標準接口的改變!

相關內容