I am preparing some class notes and I want to add the "session number" and "date of session" at the header of specific pages manually. I also want the "page number" on all pages. I am using the article document class.
For example, at page 1 header I want to have
Session 1, 19.Feb.2017
and at page 3 header I want to have
Session 2, 21.Feb.2017
How should I do this?
\documentclass{article}
\usepackage{lipsum}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\lhead{}
\chead{}
\rhead{\textbf{Session No. Date}}
\cfoot{\thepage}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\begin{document}
\section{First Section}
\lipsum[1-8]
\newpage
\section{Second Section}
\lipsum[1-4]
\end{document}
Best Answer
Here's a simple approach using
fancyhdr
and own pagestyles for this special task. This is based on your first MWE.I've just defined a new pagestyle via
\fancypagestyle
which has only one change (the rest is kept from the overall setup): it sets one head (\lhead
) to a temporary value (saved in\tmpx
). For your convenience (to not write\renewcommand{\tmpx}{}
every time) I introduced a setter-macro called\tmp
, which you have to call to set the information used in the new pagestyle.The usage is simple: On the page you want extra information on you just set them using
\tmp
and then load the other pagestyle using\thispagestyle
.