我想将所有内容保存在一个主文件中,并要求在每个命令后使用 lastpage 开始新的页码\newpage
。MWE 如下。任何帮助都将不胜感激。谢谢
\documentclass[12pt,english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage[a4paper]{geometry}
\geometry{verbose,tmargin=1cm,bmargin=1.5cm,lmargin=1cm,rmargin=1cm}
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{array}
\makeatletter
\usepackage{lastpage} % number of last page
\fancyhf{}
\fancyhead[C]{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0.5pt}
\fancyfoot[R]{Page \thepage\ of \pageref{LastPage}}
%\fancyfoot[L]{\today}
\usepackage{babel}
\usepackage{blindtext}
% Begin Document
\begin{document}
\section{Introduction}
\subsection{Intro1}
% Blind Text
\blindtext[1]
\section{Material \& Method}
% Blind Text
\blindmathpaper
\section{Introduction}
\subsection{Intro1}
% Blind Text
\blindtext[1]
\newpage
\section{Material \& Method}
% Blind Text
\blindmathpaper
\blindtext[1]
\blindmathpaper
% End Document
\end{document}
答案1
为了避免混淆,我创建了宏 \newgroup 来重置页计数器,并创建了 \thelastpage 来打印“组”的最后一页。棘手的一点是在页面结束之前设置 LastPage 标签,但直到页面结束之后(创建页眉和页脚时)才更改计数器。
\documentclass[12pt,english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage[a4paper]{geometry}
\geometry{verbose,tmargin=1cm,bmargin=1.5cm,lmargin=1cm,rmargin=1cm}
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{array}
\newcounter{group}
\makeatletter
\newcommand{\newgroup}{%
\let\@currentlabel=\empty
\label{LastPage\thegroup}% \pageref doesn't need a \refstepcounter
\newpage
\stepcounter{group}%
\setcounter{page}{1}%
}
\newcommand{\thelastpage}{\@ifundefined{r@LastPage\thegroup}%
{\pageref{LastPage}}{\pageref{LastPage\thegroup}}}
\makeatother
\usepackage{lastpage} % number of last page
\fancyhf{}
\fancyhead[C]{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0.5pt}
\fancyfoot[R]{Page \thepage\ of \thelastpage}
%\fancyfoot[L]{\today}
\usepackage{babel}
\usepackage{blindtext}
% Begin Document
\begin{document}
\section{Introduction}
\subsection{Intro1}
% Blind Text
\blindtext[1]
\section{Material \& Method}
% Blind Text
\blindmathpaper
\section{Introduction}
\subsection{Intro1}
% Blind Text
\blindtext[1]
\newgroup
\section{Material \& Method}
% Blind Text
\blindmathpaper
\blindtext[1]
\blindmathpaper
% End Document
\end{document}