You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在moderncv文档类中设置固定的总页码值?

解决方法

moderncv 内部默认通过获取文档最后一页的页码自动计算总页数,你可以通过重定义其内部的总页数变量来固定显示值,操作如下:

  1. 在文档导言区(也就是 \begin{document} 之前的位置)添加如下代码,即可将总页数固定为42:
% 固定总页数为42
\makeatletter
\renewcommand*{\@lastpage}{42}
\makeatother

如果使用的是旧版本 moderncv,上述代码不生效的话,可以替换为下面的代码:

\renewcommand*{\numberofpages}{42}
  1. 修改后的完整示例代码如下:
\documentclass[11pt,a4paper,sans]{moderncv}

\moderncvstyle{casual}
\usepackage[utf8]{inputenc}

\firstname{}
\familyname{}
\title{Curriculum Vitae}

% 固定总页数为42
\makeatletter
\renewcommand*{\@lastpage}{42}
\makeatother

\begin{document}
  \makecvtitle
  \setcounter{page}{13}

  Should be 13/42 not 13/17!
  \newpage
  Should be 14/42 not 14/17!
  \newpage
  Should be 15/42 not 15/17!
  \newpage
  Should be 16/42 not 16/17!
  \newpage
  Should be 17/42 not 17/17!
\end{document}

编译后页脚就会按照「当前页/42」的格式显示,不会再自动计算实际文档总页数。

内容的提问来源于stack exchange,提问作者Thanthla

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.13 13:36:01