# Header style with page number under bleeded rule

I'm trying to create this header style in a memoir document (this is a mock-up in Inkscape):

I thought of tikz, and I've seen this cool one, but I'm thinking this isn't so complex and tikz for every header is perhaps overkill.

I can't think of how to do this:

• page number under the head rule in a color box
• rule and page number bleeding 3mm into the margins

I have got this far:

The layout and so on code is on Github, ready to compile. The part dealing with the headers is in theheaders.sty:

\nouppercaseheads

\newlength\BOOK@bleed
\setlength{\BOOK@bleed}{3mm}

\newlength\BOOK@footWidth

% TODO: header should bleed on each side
\setlength{\BOOK@footWidth}{\textwidth}

\makepagestyle{toprightnum}

\newcommand\pageNumFmt{\pageNumFont\pageNumSize\color{pagenum}}

% TODO: page number should drop under the headrule with a gray
% background

\hspace*{\foremargin}\MakeLowercase{\rightmark}}%
{}%
\MakeLowercase{\leftmark}%
\parbox[c][][t]{\foremargin}{%
\pageNumFmt%
\mbox{}\hfill\textbf{\thepage}\hfill\mbox{}%
}%
}

\parbox[c][][t]{\foremargin}{%
\pageNumFmt%
\mbox{}\hfill\textbf{\thepage}\hfill\mbox{}%
}%
\MakeLowercase{\leftmark}%
}%
{}%
\MakeLowercase{\rightmark}\hspace*{\foremargin}%
}

\makeoddfoot{toprightnum}{}{}{}
\makeevenfoot{toprightnum}{}{}{}

\makepsmarks{toprightnum}{%
\def\chaptermark##1{%
\markboth{##1}{\rightmark}}%
\def\partmark##1{%
\markright{##1}{}}%
\let\sectionmark\@gobble
}

• There is the command \raisebox{<lift>}[<extend above baseline>]{<extend below baseline>]{<text>}, which you could combine with a \colorbox{<name>}{<text>} from the graphicx package.... – jon Feb 13 '15 at 18:22

I discovered xcoffins through this design, after that it was a breeze:

\nouppercaseheads

\newlength\BOOK@bleed
\setlength{\BOOK@bleed}{3mm}

\makepagestyle{toprightnum}

\newcommand\pageNumFmt{\pageNumFont\pageNumSize\color{pagenum}}

{%
\MakeLowercase{\rightmark}%
\hfill%
\MakeLowercase{\leftmark}%
}%
}%
}%
\setlength{\fboxsep}{0pt}%
\raggedright
\hspace*{15pt}%
\pageNumFmt%
\textbf{\thepage}%
}}%
}%
}{}{}%

{%
\MakeLowercase{\leftmark}%
\hfill%
\MakeLowercase{\rightmark}%
}%
}%
}%
\setlength{\fboxsep}{0pt}%
\raggedleft
\pageNumFmt%
\textbf{\thepage}%
\hspace*{15pt}%
}}%
}%