![如何使附錄出現在目錄的部分層級?](https://rvso.com/image/266424/%E5%A6%82%E4%BD%95%E4%BD%BF%E9%99%84%E9%8C%84%E5%87%BA%E7%8F%BE%E5%9C%A8%E7%9B%AE%E9%8C%84%E7%9A%84%E9%83%A8%E5%88%86%E5%B1%A4%E7%B4%9A%EF%BC%9F.png)
在book
文件類別中,我希望有一個附錄出現在部分層級的目錄中。目錄應如下所示:
Preface
Part title
Chapter title
Chapter title
Part title
Chapter title
Chapter title
Appendix: Some title
Bibliography
Index
我知道如何包含參考書目和索引\addcontentsline{toc}{part}{...}
,我甚至知道\phantomsection
如何讓它指向 PDF 中的正確位置。
但如何說服附錄達到part
TOC 等級呢?它位於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}