如何使附錄出現在目錄的部分層級?

如何使附錄出現在目錄的部分層級?

book文件類別中,我希望有一個附錄出現在部分層級的目錄中。目錄應如下所示:

Preface
Part title
  Chapter title
  Chapter title
Part title
  Chapter title
  Chapter title
Appendix: Some title
Bibliography
Index

我知道如何包含參考書目和索引\addcontentsline{toc}{part}{...},我甚至知道\phantomsection如何讓它指向 PDF 中的正確位置。

但如何說服附錄達到partTOC 等級呢?它位於chapter最後一部分的下方。

我不在乎我是否「手工」製作附錄,即不使用 \appendix。順便說一下,我正在使用\titlesec自訂章節和部分格式。

答案1

由於您只有一個附錄,「一擊破解」應該就足夠了:

\documentclass{book}

\usepackage{etoolbox}
\makeatletter
\newcommand{\appchapter}[1]{%
  \begingroup
  \patchcmd{\@chapter}
   {\addcontentsline{toc}{chapter}}
   {\addcontentsline{toc}{part}}
   {}{}
  \patchcmd{\@chapter}
   {\addcontentsline{toc}{chapter}}
   {\addcontentsline{toc}{part}}
   {}{}
  \chapter{#1}
  \endgroup
}
\makeatother

\begin{document}

\frontmatter
\tableofcontents

\mainmatter

\chapter{Preface}

\part{Part title}
\chapter{Chapter title}
\chapter{Chapter title}

\part{Part title}
\chapter{Chapter title}
\chapter{Chapter title}

\backmatter
\appendix
\appchapter{Appendix: Some title}

\chapter{Bibliography}

\end{document}

在此輸入影像描述

相關內容