# How to color background header?

Hi!!I have made this header but I can't set the colors in the background. I'm new in Latex and I find it very difficult. Could anyone help me please??

My work is that:

\documentclass[14pt,a4paper,twoside]{book}
\usepackage[T1]{fontenc}
\usepackage{titlesec, color}
\usepackage{theorem}
\newtheorem{worked example}{Worked Example}[chapter]
\newtheorem{solution}{SOLUSION}[chapter]
\usepackage{anyfontsize}
\usepackage{amsfonts}
\usepackage{textcomp}
\usepackage{enumerate}
\usepackage{fancyhdr}
\pagestyle{fancy}

\renewcommand{\chaptermark}[1]{\markboth{\textbf{\thechapter \ | \ #1}}{}}
\renewcommand{\sectionmark}[1]{\markright{\textbf{\thesection \ | \ #1}}}
\fancyfoot{}
\renewcommand{\footrulewidth}{}

\newcommand{\hsp}{\hspace{20pt}}
\newcommand{\ntl}{\newline \newline}

\titleformat{\chapter}[hang]{\fontsize{50}{60}\bfseries\color[rgb]{0,0.5,0.75}}{\thechapter\hsp\fontsize{90}{60}\selectfont\textcolor{black}{|}\hsp}{0pt}{\Huge\bfseries}

\titleformat{\section}{\large\bfseries}{}{0pt}{\textcolor[rgb]{0,0.5,0.75}{Topic \thesection} \ }[{\titlerule[0.8pt]}]

\begin{document}
\chapter{\textcolor{black}{NUMBER}}
\section{BIDMAS.}
\thispagestyle{empty}
.
.
.
.
.
\end{document}

• Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}. Jan 21, 2017 at 20:34
• I wrote my code. I hope that helps little. My problem is that i can't set the blue and the gray boxes to the header. :-) Jan 21, 2017 at 20:54
• With \pagestyle{empty} you will not see any header or footer lines. Jan 21, 2017 at 20:59
• this command clear the first page from the headers and th footers. To the other pages i have headers normally. I added the second image . That is how my work looks. Jan 21, 2017 at 21:05
• The point of a MWE is to show the problem, not the stuff that is working and is not causing trouble. Jan 21, 2017 at 21:10

Here is solution with titleps, in the place of fancyhdr: just load titlesec with option pagestyles. You won't have to fight with marks: just use \sectiontitle and \chaptertitle when you define a new pagestyle. \thispagestyle{empty} may very well be incorporated into \titleformat[\chapter}, it will save typing it at each new chapter.

\documentclass[14pt,a4paper,twoside]{extbook}
\usepackage[utf8]{inputenc} %
\usepackage[T1]{fontenc}
\usepackage{lmodern} %
\usepackage[pagestyles]{titlesec}
\usepackage[x11names]{xcolor} %
\usepackage{theorem}
\newtheorem{worked example}{Worked Example}[chapter]
\newtheorem{solution}{SOLUTION}[chapter]
%\usepackage{anyfontsize}
\usepackage{amsfonts}
\usepackage{textcomp}
\usepackage{enumerate}

\newcommand{\hsp}{\hspace{20pt}}
\newcommand{\ntl}{\newline \newline}

\titleformat{\chapter}[hang]{\fontsize{50}{60}\bfseries\color[rgb]{0,0.5,0.75}}{\thechapter\hsp\fontsize{90}{60}\selectfont\textcolor{black}{|}\hsp}{0pt}{\thispagestyle{empty}\Huge\bfseries}

\titleformat{\section}{\large\bfseries}{}{0pt}{\textcolor[rgb]{0,0.5,0.75}{Topic \thesection} \ }[{\titlerule[0.8pt]}]

\usepackage{blindtext}

\newpagestyle{mine}{%
\setlength\fboxsep{10pt}
\colorbox{SlateGray2!40}{\parbox{\dimexpr\linewidth-2\fboxsep}{~\thechapter~|\hspace{0.75em}\chaptertitle}}][][]%
{}{}{\bfseries\colorbox{SlateGray2!40}{\parbox{\dimexpr\linewidth-2\fboxsep}{\thesection~|\hspace{0.75em}\sectiontitle}}%
\rlap{\colorbox{SteelBlue3}{\parbox{\dimexpr\marginparsep + \marginparwidth\relax}{\hspace{20pt}\color{white}\thepage\vphantom{|}}}}}
\setfoot{}{}{}
}

\pagestyle{mine}

\begin{document}

\chapter{{NUMBER}}%\textcolor{black}
\section{BIDMAS.}
\blindtext[10]

\end{document}


\headrulewidth and \footrulewidth are macros that must contain a length. 0pt is used to let the rules vanish:

\renewcommand*{\headrulewidth}{0pt}
\renewcommand*{\footrulewidth}{0pt}


Then, the example shows the \colorbox, example code (compiled with pdflatex):

\documentclass[a4paper,twoside]{book}
\usepackage[T1]{fontenc}
\usepackage{color}
\usepackage{fancyhdr}
\pagestyle{fancy}

\renewcommand{\chaptermark}[1]{%
\markboth{\textbf{\thechapter \ | \ #1}}{}%
}
\hspace{30pt}\textbf{\thepage} \hspace{20pt} %
\colorbox[rgb]{0,0.5,0.75}{\leftmark}%
}
\renewcommand{\sectionmark}[1]{%
\markright{\textbf{\thesection \ | \ #1}}%
}
\rightmark \hspace{20pt} \textbf{\thepage} \hspace{30pt}%
}
\fancyfoot{}
\renewcommand{\footrulewidth}{0pt}

\begin{document}
\chapter{\textcolor{black}{NUMBER}}
\section{BIDMAS.}
\thispagestyle{empty}

\newpage
Foo.
\newpage
Bar.
\end{document}