[Tex/LaTex] two different framed box in running head using fancyhdr

fancyhdrframedheader-footer

I would like to get the two different filled framed box in the odd and even side running head. Expected are:
enter image description here

enter image description here

my MWE is:

\documentclass{book}
\usepackage{fancyhdr}
\usepackage{tikz,lipsum}
\pagestyle{fancy}    
\begin{document}
\chapter{Chapter Title here}
\lipsum[1]
\section{A Level Head}
\lipsum[2-3]
\lipsum[4-12]
\end{document}  

How do get the two different frame box?

Best Answer

There are different ways of doing it (like using background, eso-pic packages) but you asked fancyhdr.

\documentclass{book}
\usepackage{fancyhdr}
\usepackage{tikz,lipsum}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[LE]{\hspace*{-0.2\headwidth}\colorbox{green!20}{\makebox[\dimexpr0.2\headwidth-2\fboxsep][c]{\strut\thepage}}%
               \colorbox{green}{\makebox[\dimexpr\headwidth-2\fboxsep][l]{\strut\rightmark}}}
\fancyhead[LO]{\colorbox{green}{\makebox[\dimexpr\headwidth-2\fboxsep][r]{\strut\rightmark}}%
                \colorbox{green!20}{\makebox[\dimexpr0.2\headwidth-2\fboxsep][c]{\strut\thepage}}}
\renewcommand{\headrulewidth}{0pt}
\begin{document}
\chapter{Chapter Title here}
\lipsum[1]
\section{A Level Head}
\lipsum[2-3]
\lipsum[4-12]
\end{document}

enter image description here

Related Question