每頁加上頁碼和總頁碼?

每頁加上頁碼和總頁碼?

我用來\pagestyle{plain}在每個頁面的底部添加頁碼。如果我想要「頁碼/總頁碼」或「總頁碼中的頁碼」之類的內容,我該怎麼做?

答案1

解決方案思路

  1. 使用包lastpage定義標籤LastPage,允許我們透過 引用最後一頁\pageref{LastPage}

  2. 使用fancyhdr控制你的頁腳。

解決方案

\documentclass{article}

\usepackage{lastpage}

\usepackage{fancyhdr}

\fancyfoot[C]{Page \thepage\ of \pageref{LastPage}}

% Uncomment to remove the header rule
% \renewcommand{\headrulewidth}{0pt} 

\pagestyle{fancy}

\usepackage{lipsum}

\begin{document}

\lipsum[1-10]

\end{document}

輸出

在此輸入影像描述

進一步調整

  1. 如果你真的喜歡它清楚的,也許您也想使用\renewcommand{\headrulewidth}{0pt}(並且可能是 \renewcommand{\footrulewidth}{0pt})來擺脫規則。

  2. 使用fancyhdr實際上會為你帶來大量其他控件,這應該是有益的。請參閱包文件了解更多詳情。

相關內容