2

I want to put images in the headers of all pages but the first page of a document.

Besides for the first page, on each and every odd page, I want one image; while on each and even page I want another image.

I tried to modify what is proposed here, but could not do so.

Werner
  • 603,163
  • Show us, what you try so far. I guess that you have twoside document. See fancyhdr documentation how it handle page headers at such documents (section *10 An example of two-sided printing, page 11 -- 12). – Zarko Dec 16 '21 at 06:22

1 Answers1

4

Since the page style elements are set when the page numbers are fully known, you can easily condition on whether or not you're on an odd/even page with \ifodd\value{page} <odd page>\else <even page>\fi:

\documentclass{article}

\usepackage{graphicx} \usepackage{fancyhdr} \pagestyle{fancy}% All pages will have a fancy page style \fancyhf{}% Clear header/footer \renewcommand{\headrulewidth}{0pt}% Remove header rule \fancyhead[C]{% \ifodd\value{page} \smash{\includegraphics[height=.8\baselineskip]{example-image-a}}% Center of Odd page \else \smash{\includegraphics[height=.8\baselineskip]{example-image-b}}% Center of Even page \fi } \fancyfoot[C]{\thepage}% Centre of footer

\fancypagestyle{firstpage}{% % Page style for first page \fancyhf{}% Clear header/footer \renewcommand{\headrulewidth}{0pt}% \fancyhead[C]{First page}% Header \fancyfoot[C]{\thepage}% Footer }

\usepackage{lipsum}

\begin{document}

\thispagestyle{firstpage} \lipsum[1-50]

\end{document}

A separate firstpage page style is set up an used via \thispagestyle{firstpage}.

I've \smashed the images, but you could consider changing the \headheight to suit the size of your image inclusion.

Werner
  • 603,163