[Tex/LaTex] How to make the header for each page

header-footer

I am using a template from someone else to write my statement of purpose. The header looks cool, but how can I make it appear for every page?

\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{geometry}
\usepackage{times}
\usepackage{setspace}
\usepackage[hidelinks]{hyperref}
\usepackage{xcolor}

\renewcommand\thefootnote{\textcolor{blue}{\arabic{footnote}}}

\geometry{left=2.5cm,right=2.5cm,top=1.5cm,bottom=2cm}
\setlength{\parskip}{0.5em}
\newcommand{\HRule}{\rule{\linewidth}{0.5mm}}
\newcommand{\Hrule}{\rule{\linewidth}{0.3mm}}
\makeatletter
\renewcommand{\@maketitle}{   \textit{ \vspace{-0.2 cm}\@author \hfill \@date}
\HRule
\parindent=0pt  \centering
\vspace{0.5cm}
{\Large \bfseries\textsc {\@title}}

\par
}
\makeatother



\begin{document}

\title{Statement of Purpose}
\author{ \textbf{My Name}}
\date{{\normalsize {Applicant for PhD program in XXX at XXX School}}%}
\maketitle
This is my statement of purpose.
\newpage{empty}
\end{document}

Best Answer

There is an easier way to achieve the same result, I think. You can use the package fancyhdr and work on it. I'll give you here a replica of what you were trying to achieve in your question, but there are more options you can use.

For example:

\pagestyle{fancy}
\fancyhf{}
\fancyhead[LE,RO]{}
\fancyhead[RE,LO]{}
\fancyfoot[CE,CO]{}
\fancyfoot[LE,RO]{}

E for even pages, O for odd pages, R for right, L for left, C for center.

New version

If you want to change the properties of the rule, you can add a couple of commands. I also fixed the top margin a bit. If you want to push text down, add this command before the text you want to push (including the title): \vspace*{<length>}. Here's the full code:

\documentclass[12pt]{article}
\usepackage[a4paper,left=2.5cm,right=2.5cm,top=\dimexpr15mm+1.5\baselineskip,bottom=2cm]{geometry}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{geometry}
\usepackage{fancyhdr}

\renewcommand{\headrulewidth}{.4mm} % header line width

\pagestyle{fancy}
\fancyhf{}
\fancyhfoffset[L]{1cm} % left extra length
\fancyhfoffset[R]{1cm} % right extra length
\rhead{\today}
\lhead{\bfseries My name}
\rfoot{}

\begin{document}
\begin{center}
    \fontsize{24pt}{10pt}\selectfont
    \textsc{\textbf{Statement of purpose}}
\end{center}

This is my statement of purpose...

\newpage

...still going.
\end{document}

And the result...

enter image description here


Old version

First page

enter image description here

Second page

enter image description here

Code

\documentclass[a4paper, 12pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{geometry}
\usepackage{fancyhdr}

\pagestyle{fancy}
\fancyhf{}
\rhead{\today}
\lhead{\bfseries My name}
\rfoot{}

\begin{document}

\begin{center}
    \fontsize{24pt}{10pt}\selectfont
    \textsc{\textbf{Statement of purpose}}
\end{center}

This is my statement of purpose...

\newpage

...still going.
\end{document}
Related Question