目次の一部のレベルで付録を表示するにはどうすればよいですか?

目次の一部のレベルで付録を表示するにはどうすればよいですか?

ドキュメントクラスでは、bookパート レベルの目次に表示される付録が必要です。目次は次のようになります。

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

参考文献と索引を追加する方法も知っていますし、 PDF 内の適切な場所を指すようにするコツ\addcontentsline{toc}{part}{...}も知っています。\phantomsection

しかし、付録をpart目次のレベルまで到達させるにはどうしたらよいでしょうか? 付録はchapter最後の部分の下にあります。

\appendix を使用せずに「手動で」付録を作成してもかまいません。ちなみに、私は\titlesec章とパートの書式設定をカスタマイズするために を使用しています。

答え1

付録は 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}

ここに画像の説明を入力してください

関連情報