Tengo una pregunta complementaria a esta: Quiere \addtocontents{toc} sin \addtocontents{ptc}
Utilizo el paquete titletoc y quiero agregar espacios verticales y una línea en la tabla de contenido, pero NO en el TOC parcial. Sin embargo, las líneas y los espacios aparecen en todos los TOC parciales, como se marca en rojo en la imagen siguiente. La solución en la pregunta vinculada no me funcionó porque quiero agregar un objeto y no una sección. ¿Alguien sabe cómo evitar esto?
Aquí está mi 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}
Respuesta1
Aquí hay una solución. La idea es agregar \addtocontents{toc}{\protect\myruleandspace}
donde \myruleandspace
se define con
\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}