# Page Numbering for All Pages (Top Right-Hand Side)

I am writing my thesis using the fancyhdr package and the report document class. My university requires me to number each page (including the title page) in the top right-hand side. My current code does not put page numbers on the title page and numbers the first page of the thesis in the bottom center part of the page.

Can someone help me fix this? I have no clue how to stop Latex from doing this.

• You mean the fancyhdr package, most likely. By default titlepages use the empty page style and have no page numbers – user31729 Mar 31 '18 at 19:09
• Thanks for the insight on this. I did not know. Is there another package that I can use instead? – Marvin Loiseau Mar 31 '18 at 19:11
• It is possible to use fancyhdr package, but the empty page style must be kicked out of the titlepage. the titling package allows for designing other page styles. On the other hand: A title page is an ordinary page effectively, there is no need to use \maketitle -- you can design as you like... – user31729 Mar 31 '18 at 19:14
• Are you just using plain report class or a custom class? – Alan Munn Mar 31 '18 at 19:15
• Yes, I am using the REPORT class. – Marvin Loiseau Mar 31 '18 at 19:19

The standard classes make the page style of the title page empty and the page style of the first pages of chapters plain. The simplest solution is to patch the {titlepage} environment and the \chapter macro to use the fancy pagestyle, and define that style to put page numbers in the top right corner. I've used the etoolbox package to do that.

\documentclass{report}
\usepackage{fancyhdr}
\usepackage{etoolbox}
\usepackage{lipsum}
\pagestyle{fancy}
\cfoot{}
\lfoot{}
\rfoot{}
\title{The title}
\author{An Author}
\patchcmd{\titlepage}{empty}{fancy}{}{}
\patchcmd{\chapter}{plain}{fancy}{}{}
\begin{document}
\maketitle
\setcounter{page}{2} % needed if pages are to be continuously numbered
\chapter{A chapter}
\lipsum
\end{document}


• The funny thing is that I show your picture and was looking for the page number... Thought that was lower than the screenshot :P (+1) – koleygr Mar 31 '18 at 20:05
• Wow! That worked perfectly... THANK YOU!!!! – Marvin Loiseau Mar 31 '18 at 20:22

A silly hack, of these I am used too, but sure will cause problems if for example you use a author with optional argument, or a short title of the report or whatever. But if not is an easy fix without changes in the body or usage of packages:

\documentclass{report}
\usepackage{lipsum}
\usepackage{fancyhdr}

%
\let\oldauthor\author
\let\oldtitle\title
\let\olddate\date
\def\author#1{\xdef\mtheauthor{#1}\oldauthor{#1}}
\def\title#1{\xdef\mthetitle{#1}\oldtitle{#1}}
%\def\date#1{\xdef\mthedate{#1}\olddate{#1}}
\let\oldmaketitle\maketitle
\def\maketitle{\phantom{.}\par\vspace{150pt}{\centering{\LARGE\mthetitle\par}\vspace{25pt}{\large\mtheauthor\par}\vspace{15pt}{\large\today\par}\vfill}\pagebreak}
\let\oldchapter\chapter
\makeatletter
\def\chapter{%
\@ifstar{\@Starred}{\@nonStarred}%
}
\def\@Starred{%
\@ifnextchar[%
{\GenericWarning{}{Warning: A starred section can not have parameters. I am going to ignore them!}\@StarredWith}%
{\@StarredWithout}%
}
\def\@StarredWith[#1]#2{%
\oldchapter*{#2}%
\thispagestyle{fancy}%
}
\def\@StarredWithout#1{
\oldchapter*{#1}%
\thispagestyle{fancy}%
}
\def\@nonStarred{%
\@ifnextchar[%
{\@nonStarredWith}%
{\@nonStarredWithout}%
}
\def\@nonStarredWith[#1]#2{%
\oldchapter[#1]{#2}%
\thispagestyle{fancy}%
}
\def\@nonStarredWithout#1{%
\oldchapter{#1}%
\thispagestyle{fancy}%
}
\makeatother

\title{Test title}
\author{Me and myself}

\pagestyle{fancy}
\begin{document}
\maketitle

\tableofcontents
\chapter{Test chapter}
\section{Test Sec}
\lipsum[2]
\subsection{Test Subsec}
\subsubsection{Test Subsubsec}

\setcounter{section}{32}
\section{Test Sec}
\lipsum[2]
\subsection{Test Subsec}
\subsubsection{Test Subsubsec}
\lipsum[2]

\end{document}


Output:

• @AlanMunn Thanks for noticing... Think that fixed but I will read again the post's request... Didn't... Thanks... – koleygr Mar 31 '18 at 19:59
• Added another usual hack of mine :P – koleygr Mar 31 '18 at 20:44