3

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}
\geometry{verbose,tmargin=2cm,bmargin=2cm,lmargin=2cm,rmargin=2cm, headheight=3pt, footskip=3pt}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage[colorlinks=true,urlcolor=blue]{hyperref}

\fancyhf{}
\fancyhead[C]{
\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}

LogoUAFMathStat.png is here

3

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
\newsavebox{\headbox}\savebox{\headbox}{\includegraphics[width=\textwidth]{LogoUAFMathStat}}
\setlength{\mytopmargin}{\totalheightof{\usebox{\headbox}}+2cm}
\geometry{verbose,
          tmargin=\mytopmargin,
          headheight=1.1\mytopmargin}
\usepackage{fancyhdr}
\fancyhf{}
\fancyhead[C]{\usebox\headbox}
\renewcommand{\headrulewidth}{0pt}
\pagestyle{fancy}
\begin{document}
\section{Introduction}
\blindtext[25]
\end{document}

enter image description here

  • 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
4

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.

Next, I changed your Fancyhead-definition as follows:

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

In total, the MWE could look like this:

\documentclass{article}
\usepackage{blindtext}
\usepackage{geometry}
\geometry{verbose,tmargin=7.5cm,bmargin=2cm,lmargin=2cm,rmargin=2cm, headheight=8cm, footskip=3pt}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage[colorlinks=true,urlcolor=blue]{hyperref}

\fancyhf{}
\fancyhead[C]{\includegraphics[height=6cm]{Logo}}
\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

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.