1

I am creating worksheets in which odd pages should say "Exercises" in the header while even pages should say "Solutions" in the header using documentclass article, printed twosided.

Why does this code make ALL pages say "Odd Pages for Exercises" in the header?

\documentclass[twosided]{article}

\usepackage{fancyhdr}
 \pagestyle{fancy}
 \fancyhead[CO]{\Large Odd Pages for Exercises}
 \fancyhead[CE]{\Large Even Pages for Solutions}

\begin{document}

should be odd and say so in header

\newpage

should be even and say so in header

\newpage

should be odd and say so in header

\newpage

should be even and say so in header

\end{document}
2

The issue in your case is very simple: the class option you have to use is twoside instead your used twosided. See also the warnings in the log file you got!

So with the correct code

\documentclass[twoside]{article} % <====================================

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead[CO]{\Large Odd Pages for Exercises}
\fancyhead[CE]{\Large Even Pages for Solutions}


\begin{document}

should be odd and say so in header page 1

\newpage

should be even and say so in header page 2

\newpage

should be odd and say so in header page 3

\newpage

should be even and say so in header page 4

\end{document}

you get the wished result:

result

  • Thank you! I didn't even notice that problem in the log file because TeXMaker put it in blue and the file compiled... there was no red, so I didn't even read it. – WeCanLearnAnything Apr 30 at 15:35
1

This should do it:

\documentclass[twoside]{article}

\usepackage{fancyhdr}
\fancypagestyle{somepagestyle}{
\fancyhead[CO]{\Large Odd Pages for Exercises}
\fancyhead[CE]{\Large Even Pages for Solutions}}
\pagestyle{somepagestyle}

\begin{document}

should be odd and say so in header

\newpage

should be even and say so in header

\newpage

should be odd and say so in header

\newpage

should be even and say so in header

\end{document}

Btw, the class option is twoside, not twosided.

  • Thanks! What was the purpose of the \pagestyle{...}... changes to the code? – WeCanLearnAnything Apr 30 at 15:36
  • 1
    In this code it's probably not that useful, but if you want to have more than one pagestyle throughout your document that's the syntax to use. – noibe Apr 30 at 16:18
  • And by "pagestyle", you mean templates for footers and headers, right? – WeCanLearnAnything May 6 at 0:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.