2

I'd like to add a header containing of a picture (aligned left with text), multirow text and a picture (aligned right with the text). I found fancyhdr which has an inacceptably compilcated documentation, I hope someone has experience. I'd like the complete header to have a blue background spanning over the full textwidth (therefore putting pictures in lhead and rhead doesn't seem to be useful. My markup looks like this:

\usepackage{fancyhdr}
\definecolor{arylideyellow}{rgb}{0.91, 0.84, 0.42}
\newcommand{\myboxheader}[1]{{\color{blue} #1}}
\newcommand{\mybox}[1]{\fcolorbox{gray}{arylideyellow}{#1}}
\pagestyle{fancy}
%\lhead{\colorbox{blue}{\includegraphics[height=1cm]{logo1.png} }}
\chead{\makebox[\textwidth]{\colorbox{blue}{\includegraphics[height=1cm]{logo1.png} \hfill my multiline header (multiline with \newline or \\?) \hfill \includegraphics[height=1cm]{logo2.png} }}}
%\rhead{\colorbox{blue}{\includegraphics[height=1cm]{logo2.png} }}
\cfoot{I don't care for the footer so far!}

\begin{document}
...
\end{document}

It is not moving the two pictures sufficiently to the left and to the right so that they are in line with the text borders.

I checked questions like How do you increase headrule length in fancyhdr? or http://www.latex-community.org/forum/viewtopic.php?f=45&t=6204, but they all assume that one can understand the structure of this large set of variables which are put in insufficient relation to each other in the docs, which doesn't apply to me...

Addendum from the comment:

Screenshot of the gap between logos A,B and the center part

Screenshot of the gap between logos A,B and the center part. I referred with "center part" to everything except the logos.

  • 1
    Please complete your code to make it compilable. That is much more useful than a mere fragment as it allows people to reproduce the issue by compiling a complete, small document and to play with possible solutions. – cfr May 16 '14 at 17:10

1 Answers1

1

In the example below I've used the Left header to set the blue background, and the Center header to place the two logos on either side, with a multi-line \parbox in the middle.

enter image description here

\documentclass{article}
\usepackage[paper=a6paper,margin=1cm,includeheadfoot]{geometry}% Just for this example
\usepackage{fancyhdr,xcolor,graphicx}
\definecolor{arylideyellow}{rgb}{0.91, 0.84, 0.42}
\newcommand{\myboxheader}[1]{{\color{blue} #1}}
\newcommand{\mybox}[1]{\fcolorbox{gray}{arylideyellow}{#1}}
\pagestyle{fancy}
\fancyhead[L]{\color{blue}{\rule{\textwidth}{1cm}}}% Set blue background
\fancyhead[C]{%
  \makebox[\textwidth]{%
    \includegraphics[height=1cm]{example-image-a}%
    \hfill%
    \parbox[b]{\dimexpr\textwidth-3cm}{my multi-line header of text \\ some more text}%
    \hfill%
    \includegraphics[height=1cm]{example-image-b}}}
\setlength{\headheight}{35pt}
\fancyfoot[C]{I don't care for the footer so far!}

\begin{document}
Lorem ipsum
\end{document}

You have to set \headheight depending on the size of the header contents. I just compiled, and LaTeX suggested it be "at least X pt", so I set it accordingly. You can do the same if you're using geometry outright.

The blue background (a blue rule of full width and height equivalent of the logos/1cm) is covered on both ends by the logos, since they're exactly the same height.

fancyhdr places the header contents in three boxes: the left header is in a zero-width box that overlaps to the right; the right header is in a zero-width box that overlaps to the left; the center header in a box of width \headwidth that is centered. Actually the left and right header are also in boxes of width \headwidth, but the overlap avoids getting errors in the output. A similar setup is used for the footer.

Werner
  • 603,163
  • Thanks for your answer, it brought me forward some lightyears :) There's a difference of one or two pixel at the buttom and top of the center part which is very obvious if the two logos have the exact same color. Further help is very much appreciated! – Kalle Richter May 16 '14 at 18:10
  • @KarlRichter: What is your center part? Could you include a screen shot of your current setup? – Werner May 16 '14 at 18:20
  • Good that you ask, I just saw that the gap only appears on every second zoom level in okular and evince and doesn't grow with the zoom level (up to 1600 % in okular), so you might need to zoom a little. I've no idea how to fix or even debug this... It's maybe not even an issue ot the markup! – Kalle Richter May 16 '14 at 18:48
  • @KarlRichter: PDF browsers snap the visuals to pixels, and could cause an erroneous look, while it actually does not exist. If the problem seem to be dependent on the zoom level (or doesn't scale with a difference in zoom), then it is just a viewer-issue, and not related to LaTeX. – Werner May 16 '14 at 18:54
  • After some adjustments (centering, fontsize), I'm wondering where the 35pt in \setlength{\headheight}{35pt} are coming from? – Kalle Richter May 17 '14 at 10:43
  • @KarlRichter: The third-to-last paragraph mentions this. If you don't set the length of \headheight, look at the .log from the compilation, and you'll see LaTeX mention that your header content is too large and that your \headheight should be at least X pts. Based on that, I chose 35pt. It may be different in your instance. – Werner May 17 '14 at 13:46