
Ich muss toc
unter bestimmten Bedingungen vor dem Inhaltslabel ein Wort hinzufügen titletoc
.
\documentclass[]{report}
\usepackage{titlesec, titletoc}
\newif{\ifappendix}
\titlecontents{section}% <section-type>
[2em]% <left>
{}% <above-code>
{\ifappendix \appendixname~\fi\thecontentslabel\ }% <numbered-entry-format>
{}% <numberless-entry-format>
{\titlerule*[0.75pc]{.}\contentspage}% <filler-page-format>\\
\titleformat{\section}[block]
{\hspace{\parindent}}
{\ifappendix\appendixname~\fi\thesection}
{1em}{}
\begin{document}
\tableofcontents
\section{One}
\appendixtrue
\section{Two}
\end{document}
MWE
Wie man an der Bedingung erkennen kann, \titlecontents
funktioniert es im Inneren nicht (ich habe ein rotes Wort im Bild erwartet), aber gleichzeitig funktioniert es mit \titleformat
dem Makro.
Antwort1
Wenn das Inhaltsverzeichnis gesetzt wird, \ifappendix
wird „false“ zurückgegeben. Sie müssen es \appendixtrue
auch an die .toc
Datei weitergeben.
\documentclass[]{report}
\usepackage{titlesec, titletoc}
\newif{\ifappendix}
\titlecontents{section}% <section-type>
[2em]% <left>
{}% <above-code>
{\ifappendix \appendixname~\fi\thecontentslabel\ }% <numbered-entry-format>
{}% <numberless-entry-format>
{\titlerule*[0.75pc]{.}\contentspage}% <filler-page-format>\\
\titleformat{\section}[block]
{\hspace{\parindent}}
{\ifappendix\appendixname~\fi\thesection}
{1em}{}
\begin{document}
\tableofcontents
\section{One}
\appendixtrue
\addtocontents{toc}{\protect\appendixtrue}
\section{Two}
\end{document}