Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question

3 Answers 3

\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.

share|improve this answer
    
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) –  Denilson Sá Oct 1 '10 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? –  Ulrike Fischer Oct 11 '10 at 11:31

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.

share|improve this answer
    
Geez... What does all of that mean? Care to add a small description of what's going on there, in plain English? –  Denilson Sá Aug 28 '10 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. –  Jan Hlavacek Aug 28 '10 at 14:45

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. :)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.