0

I searched some of the questions related with this subject on TeX.SX., but i couldn't manage to understand which one fits for me. I want page number to be displayed on all pages of the document; table of contents page, list of figures page, chapters' first pages ... I have added some part of the code I use :

\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}
  • You have to redefine "empty" for the fancy package, because the standard classes automatically switch to empty on pages where chapters start. The fancyhdr doc explains how this is done in one entire section. – Manuel Weinkauf Jan 22 '15 at 12:46
  • @ManuelWeinkauf s/empty/plain/g – Johannes_B Jan 22 '15 at 12:49
2

On chapter pages, the plain page style is used by default. You have to either redefine the plain page style using fancyhdr or (the easier one) make plain equal to `fancy like

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

Your code:

\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

A quick and dirty method is to remove \thispagestyle{plain} from \tableofcontents or the \chapter start - up pages using a \xpatchcmd from xpatch package.

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

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.