[Tex/LaTex] Page number position on page with table of contents

fancyhdrheader-footerpage-numberingpositioningtable of contents

I want to position page numbers in my document in top-right corner. I managed to do so using fancyhdr (see below).

\usepackage{fancyhdr}
\hypersetup{%
    pdfborder = {0 0 0}
}
\renewcommand*{\headrulewidth}{0pt}
\fancyhf{}
\rhead{\thepage}
\pagestyle{fancy}

Everything works fine, except page number on the page where I have table of contents is centered at the bottom of that page.

Does anyone know how to fix that?

Best Answer

I believe you need to edit the plain settings. For example, adding the following to the preamble may help

\fancypagestyle{plain}{%
\fancyhf{} % clear all header and footer fields
\fancyhead{} % clear all header fields
\fancyfoot{} % clear all footer fields
\fancyhead[RO]{\thepage}
\fancyhead[LE]{\thepage}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
}

Note that in the fancyhdr documentation it says that

Some LaTeX commands, like \chapter, use the \thispagestyle command to automatically switch to the plain page style, thus ignoring the page style currently in effect. To customize even such pages you must redefine the plain pagestyle.

Therefore, this includes pages like the Table of Contents.