2

I'm using fancyhdr, with a simple logo like the one below.

enter image description here

With MWE like the following:

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

% set the font of the document
\usepackage{fontspec}
\setmainfont{Arial}

\usepackage[letterpaper, left=19mm, right=19mm, top=2.54cm, bottom=2.54cm, headheight=43.6pt]{geometry}
\usepackage{titling}

\usepackage{setspace}
\setstretch{1.15}

\usepackage{xcolor}
\definecolor{my-orange}{RGB}{238,113,43}

\usepackage{graphicx}
\usepackage{tabu}

\usepackage{fancyhdr}

\fancypagestyle{my-style}{
    \fancyhf{} %Clear Everything.
    \renewcommand{\headrulewidth}{0.75pt} 
    \renewcommand{\footrulewidth}{0.75pt} 
    \fancyhead[R]{\includegraphics[width=5.15cm]{test_logo.png}}     
    \renewcommand{\headrule}{\hbox to\headwidth{%
    \color{my-orange}\leaders\hrule height \headrulewidth\hfill}}
    \renewcommand{\footrule}{\hbox to\headwidth{%
    \color{my-orange}\leaders\hrule height \headrulewidth\hfill}}  
    \fancyfoot[C]{} 
    \fancyfoot[R]{Page | \thepage}
}

\pagestyle{my-style}

\usepackage{microtype}
\usepackage{lipsum}

\begin{document}

\lipsum[1-10]

\end{document}

Compiling with XeLaTeX.

My problem is that the logo in the header is too close to the top of the page as follows:

enter image description here

I want to add padding so the logo is centred vertically within the header, is it possible to do this easily? Also should I want to artificially increase the length of the header how can I do that? I tried changing the headheight in geometry, but it didn't seem to work.

1
  • "Length of the header row" references the (horizontal) width in my opinion, which has nothing to do with headheight. So what are you referring to exactly?
    – Werner
    Commented Aug 12, 2015 at 17:42

1 Answer 1

4

You can use a \raisebox to vertically move the image to the desired location; adjust the settings according to your needs:

enter image description here

The code:

\documentclass[12pt]{article}

% set the font of the document
\usepackage{fontspec}
\setmainfont{Arial}

\usepackage[letterpaper, left=19mm, right=19mm, top=2.54cm, bottom=2.54cm,headheight=34pt,headsep=15pt,showframe]{geometry}
\usepackage{titling}

\usepackage{setspace}
\setstretch{1.15}

\usepackage{xcolor}
\definecolor{my-orange}{RGB}{238,113,43}

\usepackage{graphicx}
\usepackage{tabu}

\usepackage{fancyhdr}

\fancypagestyle{my-style}{
    \fancyhf{} %Clear Everything.
    \renewcommand{\headrulewidth}{0.75pt} 
    \renewcommand{\footrulewidth}{0.75pt} 
    \fancyhead[R]{\raisebox{-0.35\height}[0pt][0pt]{\includegraphics[width=5.15cm]{test_logo.png}}}     
    \renewcommand{\headrule}{\hbox to\headwidth{%
    \color{my-orange}\leaders\hrule height \headrulewidth\hfill}}
    \renewcommand{\footrule}{\hbox to\headwidth{%
    \color{my-orange}\leaders\hrule height \headrulewidth\hfill}}  
    \fancyfoot[C]{} 
    \fancyfoot[R]{Page | \thepage}
}

\pagestyle{my-style}

\usepackage{microtype}
\usepackage{lipsum}

\begin{document}

\lipsum[1-10]

\end{document}

Remarks

  • I changed the headheight to 29pt (your value was too large for the current contents).

  • To change the width for the header/footer or both you have the commands

    \fancyheadoffset
    \fancyfootoffset
    \fancyhfoffset
    

    Refer to the package documentation to see the synatx and examples of use.

  • I added the showframe option to geometry, so you can have a visual guideline of the page layout.

  • Change the vertical separation between the text and the header using the headsep option for geometry.

  • Don't use inputenc nor fontenc with fontspec.

An explanation on \raisebox:

\raisebox{<length>}{<content>}

will move vertically (upwards for a positive length and downwards for a negative one) <contents>.

The extended syntax

\raisebox{<length1>}[<length2>][<length3>]{<content>}

allows to trick LaTeX to think the object to be moved has height=<length2> and depth=<length3>. In my example code, LaTeX thinks is moving a box with 0pt height and depth.

5
  • Could you explain a little in your answer what raisebox is and how it works in this instance please?
    – Ben
    Commented Aug 12, 2015 at 17:41
  • Also this eliminates padding on the bottom of the logo - as shown here - i.imgur.com/uajG5Ep.png - ideally I would like some padding below before the hrule as well.
    – Ben
    Commented Aug 12, 2015 at 17:43
  • @Bem For your second comment, change the -0.5\height value in \raisebox to the desired value. Commented Aug 12, 2015 at 17:46
  • Thanks, though I still can't seem to get \fancyheadoffset, \fancyfootoffset, or \fancyhfoffset to increase the heights of the header / footer, could you possibly show how those commands work please?
    – Ben
    Commented Aug 12, 2015 at 17:51
  • @Ben I added an explanation on \raisebox. As I said in my answer, those commands control the width, not the height (your question mentioned "length" so I thought you were referring to the width.). To control the height, use headsep and/or headheight as options to geometry. Commented Aug 12, 2015 at 17:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .