# Logo as header using fancyhdr package

I want to use Logo as header in my document. However, I have not figured out how to use fancyhdr package efficiently. Text over wrap the header. Any help will be highly appreciated. Thanks

\documentclass{article}
\usepackage{blindtext}
\usepackage{geometry}
\usepackage{graphicx}
\usepackage{fancyhdr}

\fancyhf{}
\vspace*{-1.2cm}
\begin{center}
\makebox[\textwidth]{\includegraphics[width=\textwidth, height=6cm]{LogoUAFMathStat.png}}
\end{center}
}

\pagestyle{fancy}

\begin{document}

\section{Introduction}
\blindtext[25]

\end{document}


You can set the known parameter, like the side margins first, then

\savebox\headbox{\includegraphics[width=\textwidth]{logo}}


With that savebox you can now calculate the header height and add some extra as that will be the effective top margin with the calc package:

\setlength{\mytopmargin}{\totalheightof{\usebox\headbox} +1cm}


# Complete MWE

\documentclass{article}
\usepackage{blindtext,calc,graphicx}
\usepackage{geometry}
\geometry{verbose,
bmargin=2cm,
lmargin=2cm,
rmargin=2cm,
footskip=3pt}
\newlength\mytopmargin
\geometry{verbose,
tmargin=\mytopmargin,
\usepackage{fancyhdr}
\fancyhf{}
\pagestyle{fancy}
\begin{document}
\section{Introduction}
\blindtext[25]
\end{document}


• Thanks @Guilherme for your nice answer. Would appreciate if you guide me how to get fancy header on first page and after that without header. Thanks – MYaseen208 Dec 16 '16 at 2:22
• Thanks @Guilherme for your nice answer. Would appreciate if you guide me how to get fancy header on first page and after that without header with proper top alignment. Thanks – MYaseen208 Dec 16 '16 at 2:27
• @MYaseen208, tex.stackexchange.com/questions/30228/… – Guilherme Zanotelli Dec 16 '16 at 8:26

You shouldn't use width and height options in the \includegraphics command at the same time. It is sufficient, to use either one. The other dimension will be scaled accordingly, without distortion. If you use both, you have to take care to not ruin the proportions of your image. Or you can use the keepaspectratio option of graphicx, but the resulting image won't have the specified height and width, it will have the minimum dimensions to fit in a box of the specified height and width without distorcing the image proportions.

Unfortunately, I didn't have your logo file. Hence I had to use a replacement file. Nevertheless, I am sure, the problem can be found in the definition of the \geometry-command. With regard to my logo, I was able to produce something usefull with tmargin=7.5cm and headheight=8cm.

\fancyhead[C]{\includegraphics[height=6cm]{Logo}}


In total, the MWE could look like this:

\documentclass{article}
\usepackage{blindtext}
\usepackage{geometry}
\usepackage{graphicx}
\usepackage{fancyhdr}

\fancyhf{}
\pagestyle{fancy}

\begin{document}
\section{Introduction}
\blindtext[25]
\end{document}


Have fun.

• You are welcome @MYaseen208 . :-) – Jan Dec 15 '16 at 19:30
• @Jan Do note that you can set both width and height without distorcing the image. Just pass the keepaspectratio option! – Guilherme Zanotelli Dec 15 '16 at 20:18
• @GuilhermeZanotelli You are right. You can use both width and height at the same time. In those cases, it is very likely, that your image will ignore one of your arguments. In this specific case, I would have only set one argument. Either \width=\linewidth to stretch the image to the full line length, or \height=6cmto scale it to a given height ... – Jan Dec 16 '16 at 11:45
• @Jan, yes, true one Argument will be ignored (most of the times). But if you set both with keepaspectratio you don't have to worry where the Image is, it will always comply with the specifications. For instance, if your image is placed somewhere where width=\linewidth result in an height<6cm then you'll get a short Image and vice-versa. – Guilherme Zanotelli Dec 16 '16 at 11:50
• @Jan, it makes sense: "You shouldn't use only width and height options in the \includegraphics command at the same time" – Guilherme Zanotelli Dec 16 '16 at 11:51