Wie kann man dafür sorgen, dass ein Anhang auf Teilebene des Inhaltsverzeichnisses angezeigt wird?

Wie kann man dafür sorgen, dass ein Anhang auf Teilebene des Inhaltsverzeichnisses angezeigt wird?

In einer bookDokumentklasse möchte ich einen Anhang haben, der im Inhaltsverzeichnis auf Teileebene erscheint. Das Inhaltsverzeichnis sollte folgendermaßen aussehen:

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

Ich weiß, wie man die Bibliografie und den Index einbindet, \addcontentsline{toc}{part}{...}und ich kenne sogar einen \phantomsectionTrick, um sie an die richtige Stelle im PDF zu verweisen.

Aber wie bringe ich den Anhang dazu, auf die partEbene des Inhaltsverzeichnisses zu gehen? Er geht unter chapterden letzten Teil.

Es ist mir egal, ob ich einen Anhang „von Hand“ erstelle, also ohne \appendix zu verwenden. Übrigens verwende ich es, \titlesecum die Formatierung von Kapiteln und Teilen anzupassen.

Antwort1

Da du nur einen Anhang hast, sollte ein „One-Shot-Hack“ genügen:

\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}

Bildbeschreibung hier eingeben

verwandte Informationen