# How to add a picture to fancyhdr *header* (and align in the top right)?

In the MWE below, the blue square aligns according to plan, whereas the dummy-image doesn't, see screenshots below. How to re-code so that the dummy-image "A" is aligned like the blue square?

\documentclass[a4paper]{article}

\usepackage{graphicx}

\usepackage{fancyhdr}
\pagestyle{fancy}

\usepackage{xcolor}

\usepackage{lipsum}

\begin{document}

\lipsum

\end{document}


• Is there a special reason why you use picture? – Marco Daniel Jul 7 '13 at 13:31
• @MarcoDaniel Found that in the fancyhdr manual... but no, no special reason other than trying to come up with some solution... am just interested in a(n elegant) way to align the picture just like the blue square. – nutty about natty Jul 7 '13 at 13:34

Don't use picture but directly use \includegrahics:

\rhead{\includegraphics[width=1cm]{example-image-a}}


Now you should get a warning by fancyhdr about headheight:

Package Fancyhdr Warning: \headheight is too small (12.0pt):
Make it at least 24.93825pt.
We now make it that large for the rest of the document.
This may cause the page layout to be inconsistent, however.


To get rid of this, add:

\setlength\headheight{26pt}


to the preamble. This can be better done with the help of geometry package. That is a different story.

So the code will be:

\documentclass[a4paper]{article}

\usepackage{graphicx}

\usepackage{fancyhdr}
\pagestyle{fancy}

\usepackage{xcolor}

\usepackage{lipsum}
\setlength\headheight{26pt} %% just to make warning go away. Adjust the value after looking into the warning.

\begin{document}

\lipsum

\end{document}


• Thanks! dunno how I missed trying that one... ;) +1 for the "heads up" on the fancyhdr warning ! – nutty about natty Jul 7 '13 at 13:56
• @HarishKumar Believe it or not, this helped me a lot just for the warning!!!. I did not receive this warning, however only the first page was printed properly, for the rest of the document the footer was being displayed way too low. I added \setlength\headheight{200pt} and now all the pages display the same, is just question of customize the page geometry (I used the geometry package). – Hans Nov 22 '14 at 0:09

In addition to Harish's answer, I recommend using the geometry package.

\usepackage[margin=2.5cm,headheight=26pt,includeheadfoot]{geometry}


The crucial points are setting headheight to a value bigger than the one in the warning (and omitting the \setlength\headheight command) and includeheadfoot if you use a footer at the same time.

Further details can be found here and here.