mwe.zipels-cas-templates
模板定义了lastpage
用以显示总页数:
\def\lastpage{100}
\AtEndDocument{%
% \clearpage
\immediate\write\@auxout{\string\csxdef{lastpage}{\thepage}}
}
但是如果文档最后放置浮动体,则总页数只是有文字的最后一页,是什么原因呢?如何解决
下面是自己实现的一个示例代码,也会出现同样的问题:
\documentclass{article}
\usepackage{graphicx}
\usepackage{lipsum}
\makeatletter
\ExplSyntaxOn
\iow_new:N \l_lastpage_file
\file_if_exist:nTF{\c_sys_jobname_str.page}
{
\file_input:n{\c_sys_jobname_str.page}
}
{
\cs_set_eq:NN \lastpage \relax
}
\AtEndDocument{
\iow_open:Nn \l_lastpage_file{\c_sys_jobname_str.page}
\iow_now:Nx \l_lastpage_file
{
\cs_set:Npn \exp_not:N \lastpage
{
\thepage
}
}
\iow_close:N \l_lastpage_file
}
\cs_new:Npn \__first_foot:
{
\parbox[t]{\textwidth}
{
~ \hfill Page~ \thepage {} ~of~ \lastpage }
}
\cs_set_eq:NN \@evenfoot \__first_foot:
\cs_set_eq:NN \@oddfoot \__first_foot:
\ExplSyntaxOff
\makeatother
\begin{document}
\lipsum[1-50]
\begin{figure}
\centering
\includegraphics[width=\textwidth]{1}
\caption{Example image}
\end{figure}
\begin{figure}
\centering
\includegraphics[width=\textwidth]{1}
\caption{Example image}
\end{figure}
\begin{figure}
\centering
\includegraphics[width=\textwidth]{1}
\caption{Example image}
\end{figure}
\begin{figure}
\centering
\includegraphics[width=\textwidth]{1}
\caption{Example image}
\end{figure}
\end{document}
l3
语法看不懂,不过在模板中的话,可以通过条件判断\lastpage
命令是否已经定义,如果已经定义,则将定义重定义为空,并使用自己的配置,否则,直接使用自己的配置。因为你没有上传模板,所以无法给出代码。
下面是在标准文档类中的简短的例子,以供参考。
\documentclass[UTF8]{ctexart}
\usepackage{graphicx,lipsum,zhlipsum,lastpage,mwe,geometry,fancyhdr,pgffor}
\geometry{margin=2in,showframe,a4paper}
\pagestyle{fancy}
\fancyhf{}
\setlength{\headheight}{12pt}
\renewcommand{\headrulewidth}{0pt}
\begin{document}
\cfoot{Page~\thepage~of~\pageref{LastPage}}
\lipsum[1-8]
\pagenumbering{arabic}
\zhlipsum[1-4]
\foreach \x in {1,2,3} {
\begin{figure}
\centering
\includegraphics[width=\textwidth]{example-image}
\caption{Example Image \x}
\end{figure}
}
\end{document}