
Estoy trabajando en la numeración de páginas en TOC y necesito que el número de página comience desde TOC. En el ejemplo que se muestra a continuación, hay dos páginas para TOC seguidas de 2 páginas en blanco. Pero observo que el número de página en toc es 3. ¿Cómo puedo llegar a 1?
\documentclass{article}
\usepackage{etoolbox,graphicx}% http://ctan.org/pkg/{etoolbox,graphicx}
\usepackage{xcolor}
\usepackage{mdframed}
\usepackage{lipsum}
\definecolor{myblue}{RGB}{146,243,224}
\newcommand{\addstufftotoc}[2][toc]{% \addimagetotoc[<toc>]{<stuff>}
\addtocontents{#1}{#2}}
\makeatletter
\patchcmd{\l@section}% <cmd>
{\begingroup}% <search>
{\begingroup\normalfont\Large\bfseries}% <replace>
{}{}% <success><failure>
\newcommand\mdframedintoc{\par\bigskip%
\begin{mdframed}[hidealllines=true,backgroundcolor=myblue]
Some contents for the \texttt{mdframed} environment.
\end{mdframed}\par\bigskip
\begin{mdframed}% mdframed for the image
\centering
\includegraphics[height=2\baselineskip]{example-image-a}
\end{mdframed}%
}
\patchcmd{\tableofcontents}{\@starttoc{toc}}{\@starttoc{toc} \mdframedintoc} {}{}
\makeatother
\begin{document}
\mbox{}
\thispagestyle{empty}
\newpage
\mbox{}
\thispagestyle{empty}
\newpage
\tableofcontents
\thispagestyle{empty}
\clearpage
\setcounter{page}{1}
\section{First section}
\addstufftotoc{\nobreak\smallskip\protect\includegraphics[height=2 \baselineskip]{example-image-a}\par}
\section{Second section}
\addstufftotoc{\nobreak\smallskip\protect\includegraphics[height=2 \baselineskip]{example-image-b}\par}
\section{Third section}
\section*{Fourth section}
\addcontentsline{toc}{section}{\protect\numberline{}Fourth section}
\section{Last section}
\addstufftotoc{\nobreak\smallskip\protect\includegraphics[height=2 \baselineskip]{example-image-c}\par}
\section{First section}
\addstufftotoc{\nobreak\smallskip\protect\includegraphics[height=2 \baselineskip]{example-image-a}\par}
\section{Second section}
\addstufftotoc{\nobreak\smallskip\protect\includegraphics[height=2 \baselineskip]{example-image-b}\par}
\section{Third section}
\section*{Fourth section}
\addcontentsline{toc}{section}{\protect\numberline{}Fourth section}
\section{Last section}
\addstufftotoc{\nobreak\smallskip\protect\includegraphics[height=2 \baselineskip]{example-image-c}\par}
\section{First section}
\addstufftotoc{\nobreak\smallskip\protect\includegraphics[height=2 \baselineskip]{example-image-a}\par}
\section{Second section}
\addstufftotoc{\nobreak\smallskip\protect\includegraphics[height=2 \baselineskip]{example-image-b}\par}
\section{Third section}
\section*{Fourth section}
\addcontentsline{toc}{section}{\protect\numberline{}Fourth section}
\section{Last section}
\addstufftotoc{\nobreak\smallskip\protect\includegraphics[height=2 \baselineskip]{example-image-c}\par}
\section{First section}
\addstufftotoc{\nobreak\smallskip\protect\includegraphics[height=2 \baselineskip]{example-image-a}\par}
\section{Second section}
\addstufftotoc{\nobreak\smallskip\protect\includegraphics[height=2 \baselineskip] {example-image-b}\par}
\section{Third section}
\section*{Fourth section}
\addcontentsline{toc}{section}{\protect\numberline{}Fourth section}
\section{Last section}
\addstufftotoc{\nobreak\smallskip\protect\includegraphics[height=2 \baselineskip]{example-image-c}\par}
\section{First section}
\addstufftotoc{\nobreak\smallskip\protect\includegraphics[height=2 \baselineskip]{example-image-a}\par}
\section{Second section}
\addstufftotoc{\nobreak\smallskip\protect\includegraphics[height=2 \baselineskip]{example-image-b}\par}
\section{Third section}
\section*{Fourth section}
\end{document}
Respuesta1
Tienes 2 explícitos
\mbox{}
\thispagestyle{empty}
\newpage
entradas anteriores \tableofcontents
. Esto es lo que está insertando las dos páginas vacías. Si desea conservarlos aún a partir de la página uno, insértelos \pagenumbering{arabic}
inmediatamente después de la segunda entrada. De lo contrario, elimine las dos primeras entradas duplicadas y su ToC comenzará desde la página 1 de forma natural.
La razón por la que esto funciona es porque \pagenumbering
restablece el contador de páginas a uno (a través de \global\c@page \@ne
):
\def\pagenumbering#1{%
\global\c@page \@ne \gdef\thepage{\csname @#1\endcsname
\c@page}}
Por supuesto, la emisión \setcounter{page}{1}
sería similar.