# two different framed box in running head using fancyhdr

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

my MWE is:

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


How do get the two different frame box?

• You want those boxes extending to paper width? – user11232 Nov 23 '14 at 7:18
• @Harish: I want those boxes extend to text area – Balaji Nov 23 '14 at 7:19

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{}
\begin{document}
\chapter{Chapter Title here}
\lipsum[1]
\lipsum[2-3]
\lipsum[4-12]
\end{document}


• How to set \thepage should be in marginplace and chaptermarks are in end of text position. – Balaji Nov 23 '14 at 8:07
• @Balaji Like that? – user11232 Nov 23 '14 at 8:26
• If i have increase the \thepage fontsize the box is increase only \thepage. I want to increase both the boxes are same width. How do adjust that. – Balaji Nov 23 '14 at 10:54
• @Balaji: With this minimal setup, you have to do it manually. Add \vphantom{\Large\thepage} (assuming that \thepage is \Large) in the second box. – user11232 Nov 23 '14 at 12:42

Not very different from Harish's solution, but more modular.

\documentclass{book}
\usepackage{xcolor}
\usepackage{fancyhdr}
\usepackage{lipsum}

\pagestyle{fancy}

\setlength{\headheight}{16.5pt}% fancyhdr tells you the length
\fancyhf{}
\small
\makebox[0pt][r]{\balajipage{1cm}}%
}
\small
\makebox[0pt][l]{\balajipage{1cm}}%
}

\fancypagestyle{plain}{%
\fancyhf{}%
\fancyfoot[L]{\balajipage{\textwidth}}%
}

\definecolor{balajipage}{rgb}{0.90,0.93,0.53}

\newcommand{\balajipage}[1]{%
\begingroup\fboxsep=0pt
\colorbox{balajipage}{\balajistrut
\makebox[#1][c]{\thepage}%
}%
\endgroup
}
\begingroup\fboxsep=0pt
\makebox[\textwidth][s]{#1}%
}%
\endgroup
}
\newcommand{\balajistrut}{%
\vrule width 0pt
height 1.5\ht\strutbox
depth 1.5\dp\strutbox
}

\begin{document}
\chapter{Chapter Title here}
\lipsum[1]
\lipsum[2-3]
\lipsum[4-12]
\end{document}


• How do increase box in outer margin side like \thepage same size in outer margin. – Balaji Nov 24 '14 at 4:37
• @Balaji I can't understand what you mean. – egreg Nov 24 '14 at 7:38
• I have updated the image (odd side image - page no. 7). Please check the rule should go on upto paperwidth. – Balaji Nov 24 '14 at 9:22
• Use a wider length instead of \balajipage{1cm}, say \balajipage{3cm} – egreg Nov 24 '14 at 9:43

This uses tcolorbox boxes and the \pagemarkwidth length to change the widths of the boxes.

The tcolorbox approach requires more setup, but is quite configurable too...

\documentclass{book}
\usepackage{fancyhdr}
\usepackage{tcolorbox}%
\usepackage{tikz,lipsum}
\pagestyle{fancy}
\usepackage{calc}%
\newlength{\pagemarkwidth}
\setlength{\pagemarkwidth}{20pt}
\fancyhf{}
\raggedright\rightmark
\end{tcolorbox}
}
\begin{tcolorbox}[colback=yellow,arc=0mm,auto outer arc,left=0mm,right=0mm,boxrule=0mm,top=0mm,bottom=0mm,width={\pagemarkwidth}]
\centering\bfseries\thepage
\end{tcolorbox}
}

\raggedleft\leftmark
\end{tcolorbox}
}
\begin{tcolorbox}[colback=yellow,arc=0mm,auto outer arc,left=0mm,right=0mm,boxrule=0mm,top=0mm,bottom=0mm,width={\pagemarkwidth}]
\centering\bfseries\thepage
\end{tcolorbox}
}

\begin{document}

\chapter{Chapter Title here}
\lipsum[1]