19

I'm using fancyhdrpackage for headings and footers. I have defined left-header as a big image, and I want to vertically align (to the top or to the center, the default is to the bottom) the text from the right-header. How can I do that?

\usepackage{fancyhdr}
\pagestyle{fancy}

\lhead{\includegraphics[height=21mm]{some_fancy_logo.pdf}}
\chead{}
\rhead{I want to vertically align THIS text}

3 Answers 3

11
\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{fancyhdr}
\pagestyle{fancy}

\lhead{\raisebox{-0.5\height}{\includegraphics[height=21mm]{some_fancy_logo.pdf}}}

\chead{}

\rhead{I want to vertically align THIS text}

\begin{document}
abc
\end{document}

And don't ignore the warning of fancyhdr:

Package Fancyhdr Warning: \headheight is too small (12.0pt): 
 Make it at least 59.75078pt.

Use \headheight=22mm or something like this.

2
  • Nice idea... but unfortunately it doesn't work correctly. As I understand, I should use -1 for top-aligned, and -0.5 for center-aligned. Well, the raisebox seems to be off by 1em. (and sorry for the LONG delay before testing this) Commented Oct 1, 2010 at 22:18
  • Well it does work for me, I tested it. So something is different on your side: Either you changed the code or the graphic (which I don't have) inserts some border. Also I don't know what you mean by "off by 1em". "Off" relative to what? Commented Oct 11, 2010 at 11:31
1

I got a solution. It's a very ugly hack, but it works in my case (because I know in advance the height of the header).

\rhead{\parbox[b][21mm][t]{0.5\textwidth}{\raggedleft I want to vertically align THIS text}}

I'm accepting better solutions. :)

1
  • though this doesn't work if you have the LE,RO type headers and parbox internally aligns text.. there might be a way to do an if then from external header position things - raisebox does obey LE,RO but you have to do things line by line
    – baradhili
    Commented Jan 24, 2022 at 2:03
1

I think the problem is that in fancyhdr there is no easy way to communicate the width of a box in the left header to the right header. You could allocate a dimen register, place the width of the box in the left header into it, and use it in the right header, but I think much easier solution is to just place everything into the same header:

\lhead{\hbox to \hsize{%
       \hbox{\vtop{\vskip 0pt \hbox{\includegraphics[height=21mm]{some-fancy-logo.pdf}}}}%
       \hfill\hbox{\vtop{\vskip 0pt \hbox{I want to vertically align THIS text}}}}}
\chead{}
\rhead{}

You probably don't even need fancyhdr.

2
  • Geez... What does all of that mean? Care to add a small description of what's going on there, in plain English? Commented Aug 28, 2010 at 4:55
  • 2
    Rather that trying to explain it clumsily myself, I will point you yo an excellent explanation by Victor Eijkhout in his TeX by Topics, at eijkhout.net/texbytopic/texbytopic.html. You want to look at the chapter on Boxes. Commented Aug 28, 2010 at 14:45

You must log in to answer this question.

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