els-cas-templates模板文档最后放置浮动体总页数不对?

发布于 2025-02-26 21:21:26

mwe.zip
els-cas-templates模板定义了lastpage用以显示总页数:

\def\lastpage{100}

\AtEndDocument{%
%   \clearpage
   \immediate\write\@auxout{\string\csxdef{lastpage}{\thepage}}
}

但是如果文档最后放置浮动体,则总页数只是有文字的最后一页,是什么原因呢?如何解决
image.png

下面是自己实现的一个示例代码,也会出现同样的问题:

\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}

查看更多

关注者
0
被浏览
125
1 个回答
远方不远
远方不远 1天前
这家伙很懒,什么也没写!

l3语法看不懂,不过在模板中的话,可以通过条件判断\lastpage命令是否已经定义,如果已经定义,则将定义重定义为空,并使用自己的配置,否则,直接使用自己的配置。因为你没有上传模板,所以无法给出代码。

下面是在标准文档类中的简短的例子,以供参考。

image.png

image.png

image.png

\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}

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览