添加页码

添加页码

我在 TeX.SX. 上搜索了一些与此主题相关的问题,但我无法理解哪一个适合我。我希望在文档的所有页面上都显示页码;目录页、图表列表页、章节首页……我添加了我使用的部分代码:

\documentclass[12pt,twoside,fleqn]{report}
\usepackage{geometry}
\usepackage{fancyhdr}
\usepackage{tocloft}
\geometry{ a4paper, total={210mm,297mm}, left=27.5mm, right=27.5mm, top=30mm, bottom=20mm}
\pagestyle{fancy}
\fancyhead{}
\fancyfoot{}
\fancyhead[LE]{\thepage}
\fancyhead[RO]{\thepage}
\newlength{\spacelength}
\settowidth{\spacelength}{\normalfont\ }
\renewcommand{\headrulewidth}{0pt}
\addtocontents{toc}{~\hfill\textbf{Page}\par}
\addtocontents{toc}{\protect\renewcommand*\protect\addvspace[1]{}}
\setlength{\cftbeforetoctitleskip}{-1.5em}
\renewcommand\cftchapaftersnum{.}
\renewcommand{\cftpartleader}{\cftdotfill{\cftdotsep}} 
\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}}
\renewcommand{\cftsecleader}{\cftdotfill{\cftdotsep}}
\begin{document}
\pagenumbering{roman}
Some text..
\newpage
Some Text.
\newpage
\begin{center}
\tableofcontents{}
\end{center}
\chapter{IntroductioN}
\pagenumbering{arabic}
Some Text..
\newpage 
\section{section}
Some text..
\end{document}

答案1

在章节页面上,plain页面样式是默认使用的。您必须plain使用fancyhdr或(更简单的方法)重新定义页面样式,使其plain等于“fancy like

\makeatletter
\let\ps@plain\ps@fancy
\makeatother

您的代码:

\documentclass[12pt,twoside,fleqn]{report}
\usepackage{geometry}
\usepackage{fancyhdr}
\usepackage{tocloft}
\geometry{ a4paper, total={210mm,297mm}, left=27.5mm, right=27.5mm, top=30mm, bottom=20mm}
\pagestyle{fancy}
\fancyhead{}
\fancyfoot{}
\fancyhead[LE]{\thepage}
\fancyhead[RO]{\thepage}
\newlength{\spacelength}
\settowidth{\spacelength}{\normalfont\ }
\renewcommand{\headrulewidth}{0pt}
\addtocontents{toc}{~\hfill\textbf{Page}\par}
\addtocontents{toc}{\protect\renewcommand*\protect\addvspace[1]{}}
\setlength{\cftbeforetoctitleskip}{-1.5em}
\renewcommand\cftchapaftersnum{.}
\renewcommand{\cftpartleader}{\cftdotfill{\cftdotsep}}
\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}}
\renewcommand{\cftsecleader}{\cftdotfill{\cftdotsep}}

\makeatletter
\let\ps@plain\ps@fancy
\makeatother
\begin{document}
\pagenumbering{roman}
Some text..
\newpage
Some Text.
\newpage
\begin{center}
\tableofcontents{}
\end{center}
\chapter{IntroductioN}
\pagenumbering{arabic}
Some Text..
\newpage
\section{section}
Some text..
\end{document}

答案2

一种快速而又简单的方法是使用来自包的或启动页面来\thispagestyle{plain}删除。\tableofcontents\chapter\xpatchcmdxpatch

\documentclass[12pt,twoside,fleqn]{report}

\usepackage{xpatch}%
\usepackage{geometry}
\usepackage{fancyhdr}
\usepackage{tocloft}
\geometry{ a4paper, total={210mm,297mm}, left=27.5mm, right=27.5mm, top=30mm, bottom=20mm}
\pagestyle{fancy}
\fancyhead{}
\fancyfoot{}
\fancyhead[LE]{\thepage}
\fancyhead[RO]{\thepage}
\newlength{\spacelength}
\settowidth{\spacelength}{\normalfont\ }
\renewcommand{\headrulewidth}{0pt}
\addtocontents{toc}{~\hfill\textbf{Page}\par}
\addtocontents{toc}{\protect\renewcommand*\protect\addvspace[1]{}}
\setlength{\cftbeforetoctitleskip}{-1.5em}
\renewcommand\cftchapaftersnum{.}
\renewcommand{\cftpartleader}{\cftdotfill{\cftdotsep}} 
\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}}
\renewcommand{\cftsecleader}{\cftdotfill{\cftdotsep}}


\xpatchcmd{\tableofcontents}{\thispagestyle{plain}}{}{}

\makeatletter
\xpatchcmd{\@chapter}{\thispagestyle{plain}}{}{}
\makeatother

\begin{document}
\pagenumbering{roman}
Some text..
\newpage
Some Text.
\newpage
\begin{center}
\tableofcontents{}
\end{center}
\chapter{IntroductioN}
\pagenumbering{arabic}
Some Text..
\newpage 
\section{section}
Some text..
\end{document}

在此处输入图片描述

相关内容