1

I want to have my pages on the top right corner of all of my pages. However, for every \part and \chapter the page number is on the bottom middle.

My code (the numbering part) is:

\documentclass[a4paper,twoside,12pt]{report}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead{}
\fancyfoot{}
\fancyhead[R]{\thepage}
\usepackage{titlesec}
\titleformat{\chapter}[display]
   {\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{20pt}{\Huge}
\titlespacing*{\chapter}{0pt}{0pt}{10pt}
\pagenumbering{arabic}

\begin{document}
\setcounter{page}{1}
\pagenumbering{arabic}
\part{aaaaaaaa}
\chapter{bbbbbb}
\chapter{ccccc}
\section{ddddd}
\end{document}

There is way more code and of course lots of stuff written everywhere. On this example, the page number is on the bottom middle for the page with \part{aaaaaaaa}, \chapter{bbbbbb}, \chapter{ccccc}, on the top right for the rest of the document and I would like to have it on the top right corner for every pages.

Thanks a lot for your answers.

1

First pages of chapters use the plain page style. To also move the page number on these pages, you can redefine the pagestyle using \fancypagestyle{plain}{\fancyhead{}\fancyfoot{}\fancyhead[R]{\thepage}}. (See also "10 Redefining page style plain" in the fancyhdr package manual.) To additionally get rid of the warning Package Fancyhdr Warning: \headheight is too small (12.0pt): I have added \setlength{\headheight}{15pt}to your example.

enter image description here

\documentclass[a4paper,twoside,12pt]{report}
\setlength{\headheight}{15pt}
\usepackage{fancyhdr}

\pagestyle{fancy}
\fancyhead{}
\fancyfoot{}
\fancyhead[R]{\thepage}

\fancypagestyle{plain}{%
\fancyhead{}
\fancyfoot{}
\fancyhead[R]{\thepage}
}

\usepackage{titlesec}
\titleformat{\chapter}[display]
   {\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{20pt}{\Huge}
\titlespacing*{\chapter}{0pt}{0pt}{10pt}


\pagenumbering{arabic}

\begin{document}
\part{aaaaaaaa}
\chapter{bbbbbb}
\chapter{ccccc}
\section{ddddd}

\end{document}

Sincoe you are using twoside you might also be interested to use \fancyhead[RO]{\thepage}\fancyhead[LE]{\thepage} instead of \fancyhead[R]{\thepage}

2
  • Thank you very much, it works perfectly. What does \fancyhead[RO]{\thepage}\fancyhead[LE]{\thepage} does? Jul 8 '19 at 7:30
  • R and L stand for right and left, while O and E stand for odd and even. RO and LE ensure that your page numbers will always be at the outer margin if you print your document double sided.
    – leandriis
    Jul 8 '19 at 8:29

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.