\addtocontents{ptc} 없이 \addtocontents{toc}를 사용하여 줄과 공백 추가

\addtocontents{ptc} 없이 \addtocontents{toc}를 사용하여 줄과 공백 추가

이에 대한 후속 질문이 있습니다. \addtocontents{ptc} 없이 \addtocontents{toc}를 원함

나는 titletoc 패키지를 사용하고 목차에 세로 공백과 한 줄을 추가하고 싶지만 부분 TOC에는 추가하고 싶지 않습니다. 그러나 아래 그림에서 빨간색으로 표시된 것처럼 모든 부분 목차에는 선과 공백이 나타납니다. 섹션이 아닌 개체를 추가하고 싶기 때문에 연결된 질문의 솔루션이 작동하지 않았습니다. 누구든지 이것을 우회하는 방법을 알고 있습니까?

내 MWE는 다음과 같습니다.

\documentclass{article}
\usepackage{titletoc}

\begin{document}
\tableofcontents

\section{Section1}
Here the text of the document begins with Section 1.

\section{Section2}
\startcontents % Want partial TOC for Section2
\printcontents{}{1}{}
Here is the text of Section 2.
\subsection{Subsection2.1}
Here is the text of the first Subsection.
\subsection{Subsection2.2}
Here is the text of the second Subsection.
\stopcontents %Stop the contents for partial TOC

% For some reason I want a line and spaces ONLY in the MAIN TOC, not in the partial TOC
\addtocontents{toc}{\protect\addvspace{10pt} \protect{\hrule height 1.2pt} \protect\addvspace{10pt}}

\section{Section3}
\startcontents % Want partial TOC for Section3
\printcontents{}{1}{}
Here is the text of Section 3.
\subsection{Subsection3.1}
Here is the text of the first Subsection.
\subsection{Subsection3.2}
Here is the text of the second Subsection.
\stopcontents %Stop the contents for partial TOC

\end{document}

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

답변1

여기에 해결책이 있습니다. 아이디어는 다음 과 같이 정의되는 \addtocontents{toc}{\protect\myruleandspace}것을 추가하는 것입니다.\myruleandspace

\newcommand{\myruleandspace}{\addvspace{10pt} \hrule height 1.2pt \addvspace{10pt}}
\tableofcontents
\renewcommand{\myruleandspace}{}

MWE

\documentclass{article}
\usepackage{titletoc}


\begin{document}
\newcommand{\myruleandspace}{\addvspace{10pt} \hrule height 1.2pt \addvspace{10pt}}
\tableofcontents
\renewcommand{\myruleandspace}{}

\section{Section1}
Here the text of the document begins with Section 1.

\section{Section2}
\startcontents % Want partial TOC for Section2
\printcontents{}{1}{}
Here is the text of Section 2.
\subsection{Subsection2.1}
Here is the text of the first Subsection.
\subsection{Subsection2.2}
Here is the text of the second Subsection.
\stopcontents %Stop the contents for partial TOC

% For some reason I want a line and spaces ONLY in the MAIN TOC, not in the partial TOC
\addtocontents{toc}{\protect\myruleandspace}

\section{Section3}
\startcontents % Want partial TOC for Section3
\printcontents{}{1}{}
Here is the text of Section 3.
\subsection{Subsection3.1}
Here is the text of the first Subsection.
\subsection{Subsection3.2}
Here is the text of the second Subsection.
\stopcontents %Stop the contents for partial TOC

\end{document}

관련 정보