插入 PDF 时暂停页码编排,插入 PDF 后恢复

插入 PDF 时暂停页码编排,插入 PDF 后恢复

我的论文中就有这样插入的 pdf,xassoccnt在插入 pdf 之前用来存储页码,之后从这个页码开始。我用过这个答案作为起点。

\documentclass[a4paper,12pt,oneside]{report}
\usepackage[left=1.8in,right=1.2in,top=1in,bottom=1.2in]{geometry}

\usepackage[demo]{pdfpages} %using demo mode as Overleaf takes too long to compile.

\usepackage{xassoccnt}

\begin{document}
\DeclareBackupCountersGroupName{pagebackup}
\AssignBackupCounters[name=pagebackup]{page}

\chapter{Introduction}
\label{ch:introduction}

\section{Publication I}

\clearpage
\BackupCounterGroup[backup-id=pub1]{pagebackup} %store page number (page 2)
\newpage

\setlength{\originalVOffset}{\voffset}   
\setlength{\originalHOffset}{\hoffset}

\setlength{\voffset}{0cm}
\setlength{\hoffset}{0cm}
\includepdf[pages=-]{1-introduction/publication_01.pdf}
\setlength{\voffset}{\originalVOffset}
\setlength{\hoffset}{\originalHOffset}

\clearpage
\RestoreBackupCounterGroup[backup-id=pub1]{pagebackup} %should start at 3, but gives an error

\section{}
\end{document}

这导致出现错误\RestoreBackupCounterGroupMissing number, treated as zero.并且不出所料,页码pdf 现在为零。我遗漏了什么?

例如,页码应该进行;

1

2

pdfpage(无编号)

pdfpage(无编号)

pdfpage(无编号)

pdfpage(无编号)

3

4

答案1

不需要任何软件包来实现这一点。只需记录原始页码并在包含 PDF 后设置页码即可。

\documentclass[a4paper,12pt,oneside]{report}
\usepackage[left=1.8in,right=1.2in,top=1in,bottom=1.2in]{geometry}
\usepackage{mwe} % For generate the example-image.pdf
\usepackage{pdfpages} %using demo mode as Overleaf takes too long to compile.

\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% record original page number %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcounter{opagenum}
\setcounter{opagenum}{\thepage}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Introduction}
\label{ch:introduction}
\section{Publication I}


\clearpage
\newpage

\newlength{\originalVOffset}
\newlength{\originalHOffset}
\setlength{\originalVOffset}{\voffset}   
\setlength{\originalHOffset}{\hoffset}

\setlength{\voffset}{0cm}
\setlength{\hoffset}{0cm}

\includepdf[pages=-]{example-image.pdf}
\includepdf[pages=-]{example-image.pdf}
\includepdf[pages=-]{example-image.pdf}

\setlength{\voffset}{\originalVOffset}
\setlength{\hoffset}{\originalHOffset}
\clearpage

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% make the original page number plus one %
% and set it as current page number      %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\stepcounter{opagenum}
\makeatletter
\global\c@page \theopagenum
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Test1}

\clearpage
\section{Test2}
\end{document}

还有另一种方法:

\documentclass[a4paper,12pt,oneside]{report}
\usepackage[left=1.8in,right=1.2in,top=1in,bottom=1.2in]{geometry}
\usepackage{mwe} %For generate the example-image.pdf
\usepackage{pdfpages} %using demo mode as Overleaf takes too long to compile.

\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% record original page number %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcounter{opagenum}
\setcounter{opagenum}{\thepage}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Introduction}
\label{ch:introduction}
\section{Publication I}


\clearpage
\newpage

\newlength{\originalVOffset}
\newlength{\originalHOffset}
\setlength{\originalVOffset}{\voffset}   
\setlength{\originalHOffset}{\hoffset}

\setlength{\voffset}{0cm}
\setlength{\hoffset}{0cm}

\includepdf[
pagecommand={
\setcounter{page}{\theopagenum}% add command to set page number won't go up
\thispagestyle{empty}% The default code in pagecommand
},
pages=-
]{example-image.pdf}

\setlength{\voffset}{\originalVOffset}
\setlength{\hoffset}{\originalHOffset}
\clearpage
\section{Test1} %should start from opagenum + 1

\clearpage
\section{Test2}
\end{document}

相关内容