
Я работаю над нумерацией страниц в toc и мне нужно, чтобы номер страницы начинался с TOC. В примере ниже есть две страницы для TOC, за которыми следуют 2 пустые страницы. Но я заметил, что номер страницы в toc равен 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
. Это то, что вставляет две пустые страницы. Если вы хотите сохранить их, но начать с первой страницы, вставьте \pagenumbering{arabic}
сразу после второй записи. В противном случае удалите первые две дублирующие записи, и ваш ToC начнется со страницы 1 естественным образом.
Причина, по которой это работает, заключается в том, что \pagenumbering
счетчик страниц сбрасывается на единицу (через \global\c@page \@ne
):
\def\pagenumbering#1{%
\global\c@page \@ne \gdef\thepage{\csname @#1\endcsname
\c@page}}
Конечно, эмиссия \setcounter{page}{1}
будет аналогичной.