Como controlar o número da página no TOC de várias páginas?

Como controlar o número da página no TOC de várias páginas?

Estou trabalhando na numeração de páginas no TOC e preciso que o número da página comece no TOC. No exemplo abaixo, há duas páginas para o sumário seguidas por duas páginas em branco. Mas observo que o número da página no toc é 3. Como posso chegar 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}

insira a descrição da imagem aqui

Responder1

Você tem 2 explícitos

\mbox{}
\thispagestyle{empty}
\newpage

entradas antes \tableofcontents. É isso que está inserindo as duas páginas vazias. Se desejar manter aqueles que ainda começam na página um, insira-os \pagenumbering{arabic}imediatamente após a segunda entrada. Caso contrário, remova as duas primeiras entradas duplicadas e seu ToC começará naturalmente na página 1.

A razão pela qual isso funciona é porque \pagenumberingredefine o contador de páginas para um (via \global\c@page \@ne):

\def\pagenumbering#1{%
  \global\c@page \@ne \gdef\thepage{\csname @#1\endcsname
   \c@page}}

Claro, a emissão \setcounter{page}{1}seria semelhante.

informação relacionada