3

I try to vertical align a text next to an image in a fancyhdr environment. This is my LaTeX code:

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{graphicx}

\headheight=60pt
\lhead{Foo bar \\
    Baz lorem \\
    ipsum dolor}
\chead{}
\rhead{This should be vertically aligned (middle) \raisebox{-.5\height}{\includegraphics[scale=0.25]{wappen}}}

\pagestyle{fancy}
\fancypagestyle{titlestyle}
{
    \fancyhf{}
    \renewcommand{\headrulewidth}{0pt}
    \fancyfoot[C]{\Large \today}
}

\begin{document}
    Test
\end{document}

It somehow works (the text is vertically aligned), but the multi-lined text on the left is influenced: Its baseline is also shifted upwards.

How can I vertically align the text on the right without modifying the baseline of the left header?

Screenshot of PDF

0

You can do that easily with the \Centerstack command, from the stackengine package.

Here is how, with one of my own images since you didn't provide one. Also, centring text w. r. t. the image is better if you lower of 0.4\height, to take into account the height of the line of text (the exact value depend on the height of the image, of course):

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{graphicx}
\usepackage{stackengine}
\setstackEOL{\\}
\headheight=60pt
\lhead{%
\Centerstack[l]{Foo bar \\
    Baz lorem \\
    ipsum dolor}}
\chead{}
\rhead{This should be vertically aligned (middle) \raisebox{-.4\height}
{\includegraphics[scale=0.16]{Hedgehog-in-the-Fog}}}

\pagestyle{fancy}
\fancypagestyle{titlestyle}
{
    \fancyhf{}
    \renewcommand{\headrulewidth}{0pt}
    \fancyfoot[C]{\Large \today}
}

\begin{document}
    Test
\end{document} 

enter image description here

0

Put everything in the left field of the header:

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{graphicx}
\usepackage{lipsum}

\setlength{\headheight}{60pt}

\fancyhf{}
\fancyhead[L]{%
  \begin{tabular}{@{}l@{}}
  Foo bar \\
  Baz lorem \\
  ipsum dolor
  \end{tabular}\hfill
  \begin{tabular}{@{}l@{}}
  \mbox{}\\
  This should be vertically aligned (middle) \\
  \mbox{}
  \end{tabular}\quad
  \begin{tabular}{@{}c@{}}
  \includegraphics[height=40pt]{duck}
  \end{tabular}}

\pagestyle{fancy}
\fancypagestyle{titlestyle}{%
  \fancyhf{}%
  \renewcommand{\headrulewidth}{0pt}%
  \fancyfoot[C]{\Large \today}%
}

\begin{document}
\lipsum[1-15]
\end{document}

enter image description here

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.