
toc
을 사용하여 어떤 조건에 따라 내용 라벨 앞에 단어를 추가해야 합니다 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
내부 상태 에서 볼 수 있듯이 \titlecontents
작동하지 않지만(그림에서 빨간색 단어를 예상했습니다) 동시에 \titleformat
매크로에서는 작동합니다.
답변1
목차를 조판하는 동안 \ifappendix
false를 반환합니다. 파일 \appendixtrue
에도 전달해야 합니다 .toc
.
\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}