\titlecontents 내부의 \if 조건이 실패했습니다.

\titlecontents 내부의 \if 조건이 실패했습니다.

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

목차를 조판하는 동안 \ifappendixfalse를 반환합니다. 파일 \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}

여기에 이미지 설명을 입력하세요

관련 정보