1

I'm struggling to add an image to the headers of an A4 paper document. Additionnally, my document is twoside. That's the way I'd like it to look :

enter image description here

Basically the logo with the name and the triangles are one single image, spanning the full width of an A4 page (I've taken it from a Word template), and adapted to displaying on odd pages. I designed a second image for even pages.

I tried to put them in a fancyhdr style, using the command \fancyhead[\includegraphics[width=\paperwidth]{even.png}]{\includegraphics[width=\paperwidth]{odd.png}}. The thing is the image doesn't adjust to the exact edges of the page. I've tried different solutions : using \setlength commands to modify the margins; using \fancyheadoffset command to change the width of the header; splitting the image into three smaller images (triangles, inverted triangles and logo) that I could send into the corners using \fancyhead's R and L options ... None of them would work. So I figured I needed your help.

So is it even possible to set an image in the header of a document to give the output above ?

Here's a MWE :

\documentclass[a4paper,twoside]{report}

\usepackage[T1]{fontenc}
\usepackage[UTF8]{inputenc}
\usepackage{graphicx, fancyhdr, lipsum}
\usepackage[top=2.0cm, bottom=2.5cm, inner=2.5cm, outer=2.5cm, marginparwidth=0pt]{geometry}
\pagestyle{fancy}%
\fancyhf{}%
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}

% These lines are my attempts at changing the layout
%\setlength\hoffset{0pt}
%\setlength\oddsidemargin{1cm}
%\setlength\voffset{0pt}
\setlength\headheight{85.0pt}
\addtolength{\textheight}{-85.0pt}
%\setlength\headwidth{\paperwidth}
%\fancyheadoffset{150pt}
%---

\fancyhead[RE, LO]{\includegraphics{logo.png}}
\fancyhead[LE]{\includegraphics{even.png}}
\fancyhead[RO]{\includegraphics{odd.png}} %

\begin{document}

\lipsum[1-15]

\end{document}
  • Do you want this on every page of your document? – Gonzalo Medina Jun 27 '15 at 23:36
  • No, not chapter pages, and not the front page and table of contents page. But I use \thispagestyle{empty} and it isn't a problem. Why ? – oowekyala Jun 27 '15 at 23:43
  • Why don't you want to split it in two images since there's a lot of blank space between the two parts? – Bernard Jun 28 '15 at 0:25
  • That's a solution I have tried using fancyhdr commands, but it won't adjust to the edges of the page... – oowekyala Jun 28 '15 at 12:21
3

Here is a suggestion using scrlayer-scrpage instead fancyhdr. Then you can define two new layers: one for odd and one for even pages. These layers can be added to the pagestyle scrheadings. So the images will not be on chapter pages because they are using the page style plain.

\documentclass[a4paper,twoside]{report}
\usepackage[T1]{fontenc}
\usepackage[UTF8]{inputenc}
\usepackage{graphicx}
\usepackage[margin=2.5cm, top=5cm, marginparwidth=0pt]{geometry}

\usepackage{mwe}% dummy text and example images

\newsavebox\topodd
\newsavebox\topeven
\savebox\topodd{\includegraphics[height=85pt,width=\paperwidth]{example-image-A}}
\savebox\topeven{\includegraphics[height=85pt,width=\paperwidth]{example-image-B}}

\usepackage[automark]{scrlayer-scrpage}
\clearpairofpagestyles
\cfoot*{\pagemark}% page number in footer
\DeclareNewLayer[
  background,
  topmargin,
  oddpage,
  height=85pt,
  contents={\usebox\topodd}
]{top.odd}
\DeclareNewLayer[
  clone=top.odd,
  evenpage,
  contents={\usebox\topeven}
]{top.even}
\AddLayersToPageStyle{scrheadings}{top.odd,top.even}

\begin{document}
\tableofcontents
\Blinddocument
\end{document}

enter image description here

enter image description here

Note that I have enlarged the top margin to 5cm.

  • I'm having trouble using your solution. Basically I've taken exactly the code you have typed and replaced the dummy images by my image files, and I get LaTeX error : file 'scrlayer-scrpage.sty' not found... ! Emergency stop... \clearpairofpagestyles ! ==> Fatal error occured, no output file produced!. That is when my images are in the same folder as my project, but ideally I'd like to put them elsewhere and refer to them with an absolute path. When I try that I get 0 errors, 0 warnings, 0 Bad Boxes, 0 Pages bug. I don't understand. Could you help ? – oowekyala Jun 28 '15 at 16:42
  • The package scrlayer-scrpage is part of the KOMA-Script bundle since December 2013 (KOMA-Script version 3.12). Current version on CTAN is 3.17a. So may be you have to update. – esdd Jun 28 '15 at 22:10
  • Okay, the thing was I hadn't downloaded the full KOMA-script bundle, but let miktex manage the download after it saw \usepackage{scrlayer-scrpage} (don't know if it is how that works). I downloaded the full bundle with the miktex package manager, and it know works smoothly. This is definitely what I was looking for, thank you ! – oowekyala Jun 29 '15 at 19:55

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.