# Creating Custom Headers and Footers

Page headers and footers in LaTeX are defined by the \pagestyle and \pagenumbering commands.

\pagestyle defines the general contents of the headers and footers, such as where the page numbers will be printed.

\pagenumbering defines the format of the page number.

To make the headers and footers more informative, I used the fancyhdr package.

I used this command because I wanted more than just the standard header provided by default. I wanted to have different headers and footers for odd and even pages, different headers and footers for chapter pages and control over font sizes, and so on.

You define the header and footer in the stylesheet. In this case, the package fancyhdr is used with the page style fancy.

### Use the package fancyhr

The following shows the relevant section in the stylesheet that defines the headers and footers of the document.

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}


### Define the Font Used in the Header/Footer

The font defined is 9 pt Helvetica which is defined using the short form phv. The text of the headers and footers use the titlepagecolor for the background,

\newcommand{\helv}{\fontfamily{phv}
\color{titlepagecolor}
\fontseries{b}
\fontshape{n}
\fontsize{9}{11}\selectfont}


This can be a single line as follows:

\newcommand{\helv}{\fontfamily{phv}\color{titlepagecolor} \fontseries{b} \fontshape{n}\fontsize{9}{11}\selectfont}


The titlepagecolor which has been defined elsewhere in the stylesheet as:

\definecolor{titlepagecolor}{RGB}{0,38,75}


### Grab the Chapter and Section Text

The text of the chapter is pulled in using \chaptermark while the macro \thechapter pulls in the chapter number. Similarly, the text of the section heading is pulled in using \sectionmark while the macro thesection pulls in the number of the section.

\renewcommand{\chaptermark} [1] {\markboth{\helv\NoUppercase{#1}}{}}
\renewcommand{\sectionmark} [1] {\markright{\helv\NoUppercase{#1}}{}}
\renewcommand{\sectionmark}[1]{\markright{\helv\thesection.\ #1}}
\renewcommand{\chaptermark}[1]{\markboth{\helv\thechapter.\ #1}{}}


### Eliminate the Decorative Line

No decorative line is used to separate the header from the body text so it is eliminated using:

\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}


The footer, in this example, inserts a page number and copyright.

\fancyfoot[LE,RO]{\helv Page \thepage}

\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}


## Inserting fancyhead Into the Root File

After defining the headers and footers in the stylesheet, you insert the header into the root file after the \frontmatter environment command.

\begin{document}
\frontmatter
% Configuration of the header strings for the frontmatter pages.
\setcounter{tocdepth}{3}


It is important where you place this command. The LaTeX typesetter my know how to build the headers and footers before any geometry is defined. After calling the \fancyhead command, you can go ahead and input your files, and so forth.

\fancyfoot[RE,LO]{\helv Copyright \copyright 2016 Glenn J. Lea}


%\lfoot{\thepage} %\cfoot{Copyright \copyright 2016 Glenn J. Lea}