# Complete 3-part header from fancyhdr inside a single colored box

There're other previous questions about using a color background with fancyhdr so that you get a colored header and/or footer. However, they discuss either using a different color box for each part of the header, or working with a single part header (i.e: a header with just the center part, for example).

But what if I have a complete header with three parts (left, center, and right), and I want all the three parts inside a single colored box?

Ideally, the colored box should have no margins, but the three header parts should keep their original margins, so I guess I cannot use the fancyhdr margin parameters for that.

I really need to use fancyhdr for the header. I can add more packages if necessary, but the header must still be created with fancyhdr.

Unfortunaly there is no MWE in the question. So here is only a suggestion that works for a simple three part header using package fancyhdr.

\documentclass{book}
\usepackage{xcolor}

\usepackage{fancyhdr}
\pagestyle{fancy}
Left part (even page)}
Left part (odd page)}

\usepackage{blindtext}
\begin{document}
\blinddocument
\end{document}


\documentclass{book}
\usepackage{xcolor}

\usepackage[
]{scrlayer-scrpage}
\clearpairofpagestyles

\DeclareNewLayer[
background,
contents={\color{blue!20}\rule[-\dp\strutbox]{\layerwidth}{\layerheight}}

\usepackage{blindtext}
\begin{document}
\blinddocument
\end{document}


Or starting with KOMA-Script version 3.19

\documentclass{book}
\usepackage{xcolor}

\usepackage[
]{scrlayer-scrpage}
\clearpairofpagestyles

\DeclareNewLayer[
background,
mode=picture,
contents={\putLL{\color{blue!20}\rule{\layerwidth}{\layerheight}}}

\usepackage{blindtext}
\begin{document}
\blinddocument
\end{document}


With scrlayer-scrpage it is also easy to color the top margin including the header.

\documentclass{book}
\usepackage{xcolor}

\usepackage[
]{scrlayer-scrpage}
\clearpairofpagestyles

\DeclareNewLayer[
background,
topmargin,
contents={\color{blue!20}\rule{\layerwidth}{\layerheight}}

\usepackage{blindtext}
\begin{document}
\blinddocument
\end{document}


If you want to use fancyhdr instead you can draw the background image using TikZ with the remember picture,ovelay options. So you have to run the code twice to get the rectangle on the right position.

\documentclass{book}
\usepackage{tikz}

\usepackage{fancyhdr}
\pagestyle{fancy}
\tikz[remember picture,overlay,baseline]
\fill[blue!20](current page.north west|-0,-\dp\strutbox)
rectangle(current page.north east);%
Left part (even page)}
\tikz[remember picture,overlay,baseline]
\fill[blue!20](current page.north west|-0,-\dp\strutbox)
rectangle(current page.north east);%
Left part (odd page)}