複数ページの目次でページ番号を制御するにはどうすればよいでしょうか?

複数ページの目次でページ番号を制御するにはどうすればよいでしょうか?

私は目次のページ番号付けに取り組んでおり、ページ番号は目次から始まる必要があります。以下の例では、目次が 2 ページあり、その後に空白ページが 2 ページあります。しかし、目次のページ番号は 3 になっています。これを 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}

ここに画像の説明を入力してください

答え1

明示的な2つの

\mbox{}
\thispagestyle{empty}
\newpage

前のエントリ\tableofcontents。これが 2 つの空白ページを挿入するものです。これらのページを保持しながら 1 ページ目から開始する場合は、\pagenumbering{arabic}2 番目のエントリの直後に挿入します。それ以外の場合は、最初の 2 つの重複エントリを削除すると、目次は自然に 1 ページ目から始まります。

これが機能する理由は、\pagenumberingページ カウンターを 1 にリセットするためです (経由\global\c@page \@ne)。

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

もちろん、発行も\setcounter{page}{1}同様です。

関連情報