[Tex/LaTex] how to put header (and footer) on title page with correct positioning

fancyhdrheader-footer

I tried to use fancyhdr package and the result I have with the output is as shown here. The screenshot shows the junction between pages (bottom of) 3 and (top of) 4 (both header and footer being the same; with lfoot and lhead being "Lecture 1" and rfoot and rhead being "Handout 1").

As you might notice, both header and footer are placed leftwards (taking the page number along with them).

Also, they do not appear on the title page whereas unlike most other cases, I would like them to be present on it.

MWE below:

\documentclass[10pt]{article}

\usepackage{soul}
\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{Lecture 1}
\rhead{Handout 1}
\lfoot{Lecture 1}
\rfoot{Handout 1}

\usepackage[margin=0.5in]{geometry}
\def\changemargin#1#2{\list{}{\rightmargin#2\leftmargin#1}\item[]}
\let\endchangemargin=\endlist 
\title{\ul{Proper positioning of headers and footers}}
\usepackage{lipsum}
\begin{document}
\maketitle
\lipsum[4-57]
\end{document}

Best Answer

In order to get fancyhdr to obey your geometry settings you need to call geometry first.

And to get the title page to use the same style as the rest, use \thispagestyle after \maketitle.

\documentclass{article}
\usepackage[a4paper,margin=1in]{geometry}
\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{Lecture 1}
\rhead{Handout 1}
\lfoot{Lecture 1}
\rfoot{Handout 1}
%\def\changemargin#1#2{\list{}{\rightmargin#2\leftmargin#1}\item[]}
%\let\endchangemargin=\endlist 
\title{Proper positioning of headers and footers}
\usepackage{lipsum}
\begin{document}
\maketitle
\thispagestyle{fancy}
\lipsum[4-57]
\end{document}

I used 1in margins because 0.5in is just too small. I also added a4paper but you can ignore that if you use another size. The top of the output looks like this:

enter image description here

Normally you use \thispagestyle to change the page style temporarily, so for example you might want to change to plain or empty for certain pages later in the document, but here I've made a temporary change to override the page style that's set by \maketitle. Note that the page style in force at the end of the page is the one used (since the headers and footers are added by the output routine when it ships out a page).