# Preserve page numbering and name of general section in document

I use the \pagestyle{fancy} and \fancyhf{} for my document in order to have headers/footers in my document but with the use of them, I do not get the page numbers. When I unload the fancyhf{} I get the page numbers but I also get the name of sections and subsection on the headers so I have the following questions :

1. How can I get the page numbers?

2. How can I have only the name of the general sections and not of the subsections, on the headers ?

Thank you all.

These are all the packages I use :

\documentclass[12pt,a4paper]{article}
\usepackage{amsthm}
\usepackage{titling}
\usepackage[utf8]{inputenc}
\usepackage{tcolorbox}
\usepackage{graphicx}
\usepackage{lipsum}
\usepackage{mwe}
\usepackage{subfig}
\usepackage{float}
\usepackage{cite}
\usepackage{mathtools}
\usepackage{multicol}
\usepackage{stfloats}
\usepackage{authblk}
\usepackage{afterpage}
\usepackage[T1]{fontenc}
urlcolor  = blue,
citecolor = blue,
anchorcolor = blue]{hyperref}
\usepackage{amsfonts}
\usepackage{fancyhdr}
\usepackage{pdflscape}
\usepackage{array,ragged2e,booktabs}
\usepackage{tikz}
\usepackage{longtable}
\usepackage{capt-of}
\usepackage{tabularx}
\usetikzlibrary{shapes.geometric, arrows}
\pagestyle{fancy}
\fancyhf{}

\begin{document}
\title{\vspace{-3.0cm}\rule{\textwidth}{1pt}\\title here\\\vspace{1.0cm}\rule{\textwidth}{1pt}\\{initial analysis}}
\author{author \thanks{organisation}}

\maketitle
\newpage
\tableofcontents
\newpage
\renewcommand{\thesection}{\arabic{section}}
\section{Introduction}
The visit to the area of interest
\subsection{Methods}
In order to analyse the ....
\subsubsection{Processing of data}
For the analysis of out data ...
\section{Initial results and Current work}
Respecting the current work, ....
\section{References}
References here
\end{document}

• You can try with \lhead{} \rhead{} instead of fancyhf{}. Please also turn your code fragment into a minimal working example (MWE) by removing all unnecessary packages and by including some dummy section headings in the body of the document. This way it is much easier to reproduce the problem and find a solution. Jun 10 '18 at 14:22
• Unrelated, but please avoid loading packages twice and keep in mind the correct loading order of packages if you use hyperref. This packages should generally (with some few exceptions) be the last package you load. Jun 10 '18 at 14:24
• Either don't use \fancyhf{} or add \cfoot{\thepage}. Jun 10 '18 at 14:30
• @leandriis Thank you very much for your suggestions. The reason why I provide the code with all the packages, is because as a new user I do not know whether any of the packages I use, cause the issues that I have. Can you please turn your comment as answer? Thank you a lot! Jun 10 '18 at 14:35
• @geo_dd: Thanks for editing your question to include a compilable example. You can quite easily find out which packages are needed for a MWE, if you comment them out successively and recompile after each commented out package. If the output is still the same, the package was not needed. With your preamble, you can even make your life even more easy by commenting out all af the various packages related to math and tables, as your question is about headers and footers, that don't contain math and tables. With the remaining packages you can repeat the above described procedure. Jun 10 '18 at 15:09

In a single sided socument, fancyhdr defaults to the following definition, including the current section and subsection in the right and left header respectively, as well as the pagenumber in the center of the footer:

\fancyhead[L]{\textsl{\rightmark}}
\fancyfoot[C]{\thepage}


The command \fancyhf{} that you used, removes all entries from the header and footer, thus also removing the page number.

In order to remove only the header, you can use \fancyhead{} that will leave the pageumber in the footer untouched.

Alternatively, you can also first remove all entries from headers and footers with \fancyhf{} and later on add the pagenumber (as suggested by John Kormylo in the comments) by either using \fancyfoot[C]{\thepage} or \cfoot{\thepage}

The following is a MWE that demonstrates the usage of \fancyhead{}:

\documentclass[12pt,a4paper]{article}

\usepackage{lipsum}
\usepackage{fancyhdr}
\pagestyle{fancy}

\begin{document}
\section{test}
\subsection{bla}
\lipsum
\end{document}


The following code is a MWE that demonstrates how to add the pagenumber:

\documentclass[12pt,a4paper]{article}

\usepackage{lipsum}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyfoot[C]{\thepage}

\begin{document}
\section{test}
\subsection{bla}
\lipsum
\end{document}