# How do I create a header that has a colored box with page number, Chaptername, and also a line across the textwidth after it?

I would like to create a fancy header that looks like this. I am writing a two-sided book with a5paper.

• Welcome to TeX.SX! Is this for the page header or the chapter heading? – egreg May 6 '15 at 7:02
• My apologies for the unclear question. It is for the page header of the book. – pyro May 6 '15 at 11:59

## scrlayer-scrpage

Here is a suggestion using scrlayer-scrpage.

\documentclass[a5paper]{book}

\usepackage{xcolor}

\usepackage[markcase=noupper]{scrlayer-scrpage}
\clearpairofpagestyles
\automark[chapter]{chapter}
\renewcommand\chaptermarkformat{\chaptername\ \thechapter:\enskip}

\makebox[0pt][r]{
}
\makebox[0pt][l]{%
}

\usepackage{blindtext}% dummy text
\begin{document}
\blinddocument
\end{document}


If the chapter page should not get the header remove the stars after \lehead and \rohead.

## fancyhdr

And here is an example using fancyhdr

\documentclass[a5paper]{book}

\usepackage{xcolor}

\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand\chaptermark[1]{\markboth{\chaptername\ \thechapter:\enskip#1}{}}
\fancyhf{}

\makebox[0pt][r]{
}
\makebox[0pt][l]{%
}

\usepackage{blindtext}% dummy text
\begin{document}
\blinddocument
\end{document}


If the chapter page should get the same header you have to redefine the fancypagestyle plain, too.

\fancypagestyle{plain}{
\fancyhf{}
\makebox[0pt][r]{

• @pyro I have changed the fancyhdr example: now the page numbers should have normal font on both even and odd pages. – esdd May 7 '15 at 7:44