文章类别:如何消除页码并让 \thepage 工作

文章类别:如何消除页码并让 \thepage 工作

在我的 .tex 上,我使用 article 文档类。它(默认情况下)将页码放在页面底部。但我还使用 \thepage 变量将页码放在页面顶部的特定位置。我会隐藏 article 类放在底部的页码。所以我尝试了 \pagenumbering{gobble} 并且它有效,但它也消除了 \thepage 页码变量。

我怎样才能抑制 documentclass {article} 页码,但不抑制 \thepage 变量?

答案1

即使没有 fancyhdr,修改页面样式也不是那么困难。

\documentclass{article}
\usepackage{lipsum}% random text

\makeatletter
\def\ps@plain{\let\@mkboth\@gobbletwo
  \let\@oddfoot\@empty
  \def\@oddhead{\reset@font\hfil\thepage\hfil}%
  \let\@evenfoot\@empty
  \let\@evenhead\@oddhead}
\makeatother
\pagestyle{plain}% activate new definition

\begin{document}
\lipsum[1-20]
\end{document}

如果某些页面的样式过于单调:

\documentclass{article}
\usepackage{lipsum}% random text

\makeatletter
\let\ps@plain=\ps@empty
\makeatother
\pagestyle{empty}

\begin{document}
\lipsum[1-20]
\end{document}

相关内容