8

Is there a way to add a header image in LaTeX that spans the entire page and ignores margins? I tried

\lhead{\includegraphics{image.png}}

But this considers margins, and so I still get a lot of whitespace at the top of the page. So, is there a way to have these images ignore whitespace?

  • Correct if I'm wrong, you want an image to span from your header upwards, I assume as wide as the page, right? – mirkom Mar 04 '16 at 03:43
  • See also http://tex.stackexchange.com/questions/276358/text-on-background-image-footer-and-header/276453?s=4|0.9641#276453 – John Kormylo Mar 04 '16 at 05:24

2 Answers2

5

Perhaps something like this:

Big header

I let tikzpagenodes do the math so that you can change all the settings you want in geometry and fancyhdr such as top or headersep and so on. You will need to compile twice:

\documentclass{report}
\usepackage{fancyhdr}
\usepackage[left=4cm,top=10cm,right=3cm,bottom=3cm]{geometry}
\pagestyle{fancy}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{tikzpagenodes}
\renewcommand{\headrulewidth}{0pt}
\lhead{\begin{tikzpicture}[remember picture,overlay]
\draw  let \p1=($(current page.north)-(current page header area.south)$),
      \n1={veclen(\x1,\y1)} in
node [inner sep=0,outer sep=0,below right] 
      at (current page.north west){\includegraphics[width=\paperwidth,height=\n1]{img}};
\end{tikzpicture}}
\begin{document}
\section{First section}
Type your document as usual!
\newpage
\section{Second section}
Type your document as usual!
\end{document}

I had trouble finding the distance between the header text and the headrule, so I've zeroed its thickness as I thought you won't need it.

mirkom
  • 1,664
0

I tried adjusting the left header width to various values and all of them worked for me. You can tweak this to suit you needs.

(Adjusting both the image width and height at the same time is a bad idea, and highly discouraged. This was done here for experimental purposed only.)


\documentclass[a4paper]{article}

\usepackage{fancyhdr}

\usepackage{graphicx}

\fancyhf{}
\fancyhead[L]{\includegraphics[width=0.25\textwidth,height=5.0mm]{latex.png}}

\setlength{\headheight}{7.50mm}
\pagestyle{fancy}

\usepackage{lipsum}

\begin{document}

\section{Short Width Left Header}

\lipsum[1-5]

\clearpage

\fancyhead[L]{\includegraphics[width=0.50\textwidth,height=5.0mm]{latex.png}}

\section{Mid Width Left Header}

\lipsum[1-5]

\clearpage

\fancyhead[L]{\includegraphics[width=1.00\textwidth,height=5.0mm]{latex.png}}

\section{Full Width Left Header}

\lipsum[1-5]


\end{document}

enter image description here

enter image description here

enter image description here

Masroor
  • 17,842