# Exam class: Header on odd pages - including first - footer on all

How do I get my header to appear on only the odd pages, including the first one, and my footer to appear on all pages? I'm using the exam and I have a title with \maketitle. I've tried various things. Currently my code looks like this

\pagestyle{headandfoot}
\footrule
\lfoot{Test 1: Ch 1.5 through 3.4}
\cfoot{}
\rfoot{Page \thepage\ of \numpages}


But that's printing header and footer on all pages except the first one. I did not understand any of the hacks I found on the web.

• Easier for people to help if you provide a complete(!) but minimal example (or here): it is hard to know what class or packaages you are using and some of them might have an effect on headers and footers. As for skipping the even header, is this a one- or two-sided document?
– jon
Oct 20 '13 at 3:25

You can use the \oddeven command. That command takes two arguments; the first is used on odd numbered pages and the second is used on even numbered pages. Thus, you'd use something like

  \newcommand{\myleft}{\makebox[.5\textwidth][l]{Name:\enspace\hrulefill}}
\newcommand{\myright}{\makebox[.25\textwidth][r]{Date:\enspace\hrulefill}}
{\hfill}
{\oddeven{\myright}{\hfill}}


Edit: Actually, all those \hfill's are unnecessary; you can just use

\newcommand{\myleft}{\makebox[.5\textwidth]{Name:\enspace\hrulefill}}
\newcommand{\myright}{\makebox[.25\textwidth]{Date:\enspace\hrulefill}}
{}
{\oddeven{\myright}{}}


Edit: Here are two complete LaTeX files, both of which work when I test them. The first uses \lhead, \rhead, etc., and the second uses \header.

\documentclass{exam}

\newcommand{\myleft}{\makebox[.5\textwidth]{Name:\enspace\hrulefill}}
\newcommand{\myright}{\makebox[.25\textwidth]{Date:\enspace\hrulefill}}

\footrule
\lfoot{Test 1: Ch 1.5 through 3.4}
\cfoot{}
\rfoot{Page \thepage\ of \numpages}

\begin{document}

Here's the first page.
\newpage

Here's the second page.
\newpage

Here's the third page.
\newpage

Here's the fourth page.
\newpage

\end{document}


Here's the second LaTeX file:

\documentclass{exam}

\newcommand{\myleft}{\makebox[.5\textwidth]{Name:\enspace\hrulefill}}
\newcommand{\myright}{\makebox[.25\textwidth]{Date:\enspace\hrulefill}}
{}
{\oddeven{\myright}{}}

\footrule

\footer{Test 1: Ch 1.5 through 3.4}
{}
{Page \thepage\ of \numpages}

\begin{document}

Here's the first page.
\newpage

Here's the second page.
\newpage

Here's the third page.
\newpage

Here's the fourth page.
\newpage

\end{document}


• That got the header to print on only the odd pages, except the first one. How do I force the header on the first page?
– Jeff
Oct 21 '13 at 0:41
• @jeff It works when I test it. Are you sure you used \header, and not \runningheader? \runningheader would affect all pages except the first. Oct 21 '13 at 5:23
• Oops, I didn't notice your reply till now (sorry). I'm using lhead{\oddeven{\myleft}{\hfill}}, and rhead.... Is that the problem?
– Jeff
Nov 5 '13 at 17:26
• @jeff That should work, but in your original question you have the optional argument [0] in the command \lhead, which won't work, since that optional argument is used for page 1. If you're sure to omit the optional argument in both \lhead and \rhead, it should work. You an also just use the command \header as in my answer. Nov 6 '13 at 3:54
• @jeff If you want to use the \maketitle command, you should immediately follow it with \thispagestyle{headandfoot}, since the \maketitle command changes the page style of that page to plain. Putting in the \thispagestyle{headandfoot} will change it back to headandfoot, which is the default for the exam class. Nov 9 '13 at 4:57