# Making a header width cover whole page

I need to have a header for even and odd pages like this:

I have done this so far:

% !TEX TS-program = xelatex
% !TEX encoding = UTF-8
\documentclass{biditufte-book}
\usepackage{ptext}
\usepackage{xcolor}

\usepackage{showframe}

\usepackage{fancyhdr} % Required for header and footer configuration

\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{\normalsize\bfseries #1}{}} % Chapter text font settings
\renewcommand{\sectionmark}[1]{\markright{\normalsize\bfseries #1}{}} % Section text font settings
\renewcommand{\headrulewidth}{0pt}
\setlength{\headheight}{16.5pt}% fancyhdr tells you the length

\newlength{\bluerulelength}
\setlength{\bluerulelength}{\textwidth}
\addtolength{\bluerulelength}{\marginparsep}
\addtolength{\bluerulelength}{\marginparwidth}

\newlength{\pagenumberboxskip}
\setlength{\pagenumberboxskip}{-\bluerulelength}
\addtolength{\pagenumberboxskip}{1cm}
\addtolength{\pagenumberboxskip}{10pt}

\fancyhf{}
\fancyhead[LE]{%
\small
\makebox[-5pt][r]{ \pagenumbox{1cm}}%
\pagehead{\quad\quad\quad\quad\nouppercase{\leftmark}\hfill}%
}
\fancyhead[LO]{%
\small
\makebox[\pagenumberboxskip][r]{ \pagenumbox{1cm}}%
\pagehead{\hfill\nouppercase{\rightmark}\quad\quad\quad\quad}%
}

\newcommand{\pagenumbox}[1]{%
\begingroup\fboxsep=0pt
\colorbox{blue!20}{\pagestrut
\makebox[#1][c]{\thepage}%
}%
\endgroup
}
\newcommand{\pagehead}[1]{%
\begingroup\fboxsep=0pt
\colorbox{blue}{\pagestrut
\makebox[\bluerulelength][s]{#1}%
}%
\endgroup
}
\newcommand{\pagestrut}{%
\vrule width 0pt
height 1.5\ht\strutbox
depth 1.5\dp\strutbox
}
% Removes the header from odd empty pages at the end of chapters
\makeatletter
\renewcommand{\cleardoublepage}{
\clearpage\ifodd\c@page\else
\hbox{}
\vspace*{\fill}
\thispagestyle{empty}
\newpage
\fi}

\usepackage[localise=on]{xepersian}
\settextfont{Times New Roman}
\setdigitfont{Times New Roman}

\begin{document}
\chapter{مشاهده‌‌پذیری}
\ptext
\section{مقدمه}
\ptext[1-10]
\section{مقدمه}
\ptext[1]
\end{document}


which creates something like this:

But that's not what I want. Can someone help me?

• One solution is to use negative \hspace before and after a minipage{paperwidth}. Alternatively one can use the everypage and tikzpagenodes. See tex.stackexchange.com/questions/276358/… – John Kormylo Dec 20 '16 at 15:26
• Normally you would use \fancyhfoffset[L]{some length} to shift the header to the left. And some length would probably be the sum of \hoffset and \oddsidemargin (or \evensidemargin). However bidi fiddles with fancyhdr and that no longer works. Now you have to use R instead of L. I would suggest you try something like \fancyhoffset[RE}{some value} and \fancyhfoffset[RO]{other value}, and just with trial and error (and measuring) find out what these values should be. And you have to put that after the \begin{document}. – Pieter van Oostrum Dec 20 '16 at 18:39

## 1 Answer

The bidi stuff makes some changes to fancyhdr, to accomodate bidi typesetting. For me it's confusing because I am not familiar with bidi. So for example to offset the headers on the left, normally in fancyhdr you use \fancyhfoffset[L]{some length}. But with the bidi stuff you have to use \fancyhfoffset[R]{some length}. And also how the headers behave is different. Maybe there also L and R are swapped. Anyway I have tried to make a solution, but it contains some lengths that I have found with trial and error, and I really don't know where these numbers come from.

Also I got rid of \bluerulelength and \pagenumberboxskip. I thought the blue box could be made \paperwidth long, because that would fill the whole width of the page, but I had to add 2 cm to get it right. Anyway, here is something that might work. If you know how the various length should be interpreted, please let me know.

\setlength{\headheight}{18pt}% fancyhdr tells you the length

\newcommand{\oddoffset}{81mm} % Why? I don't know
\newcommand{\evenoffset}{26mm}

\fancyhf{}
\AtBeginDocument{%
\fancyhfoffset[RO]{\oddoffset}%
\fancyhfoffset[RE]{\evenoffset}%
}

\fancyhead[LE]{%
\small
\pagehead{\hspace*{\evenoffset}\pagenumbox{1cm}\quad\nouppercase{\leftmark}\hfill}%
}
\fancyhead[LO]{%
\small
\pagehead{\hfill\nouppercase{\rightmark}\quad\pagenumbox{1cm}\hspace*{42mm}}%
}

\newcommand{\pagenumbox}[1]{%
\begingroup\fboxsep=0pt
\colorbox{blue!20}{\pagestrut
\makebox[#1][c]{\thepage}%
}%
\endgroup
}
\newcommand{\pagehead}[1]{%
\begingroup\fboxsep=0pt
\hspace*{-\evenoffset}%
\colorbox{blue}{\pagestrut
\makebox[\paperwidth+2cm][s]{#1}%
}%
\endgroup
}