[Tex/LaTex] fancy header and footer

fancyhdrheader-footer

Please can you help me to get the same result as photos. I want in my header the title of chapter and a little box with number of chapter in it, with a specific color and hrule with the same color. In my footer I want a rectangle with the same color as the box in header with page number in it. The same header and footer in the second chapter and third and fourth chapter but just with different colors.Thank you so much in advance. I will really appreciate your help its for my thesis.

ps for numberless chapters such as introduction, table of contents, list of tables… I want the same footer and header with color black and of course without the chapter number in the header box.

\documentclass[a4paper,12pt]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc} 
\usepackage{lmodern}
\usepackage{emptypage} % 
\usepackage[french]{babel}
\usepackage[top=3cm,bottom=1cm,left=2.5cm,
 right=2.5cm,headheight=26pt,headsep=25pt,heightrounded]{geometry}
\frenchbsetup{FrenchFootnotes=false} 
\usepackage[hang,flushmargin]{footmisc}
\usepackage{enumerate}          % personnaliser les listes
\usepackage[babel,french=guillemets]{csquotes}           
\usepackage{graphicx}
\setcounter{tocdepth}{5}   
\setcounter{secnumdepth}{5}
\usepackage[titles]{tocloft}
\graphicspath{{\images}}
\usepackage[table]{xcolor}
\usepackage{booktabs} 
\usepackage{xfrac}
\usepackage{refcount}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\usepackage{tikzpagenodes}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{xspace}
\usepackage{array}
\definecolor{c1}{rgb}{0,0,1}   %blue
\definecolor{c2}{rgb}{0,0.3,0.9}   %light blue
\definecolor{c3}{rgb}{0.3,0,0.9}   %red blue
\usepackage{setspace}  %interligne 1.5
\usepackage[parfill]{parskip}  
\usepackage{calc}
\usepackage{titlesec}
\usepackage{shorttoc}
\usepackage{enumitem} % modifier et personaliser les puces des listes
\usepackage{pifont} % les symboles pour les listes 
\usepackage{etoolbox}
\usepackage{sectsty} % 
\allsectionsfont{\raggedright}
\AtBeginEnvironment{footcitedquote}{\singlespacing\small}
\AtBeginEnvironment{fancyquotes}{\small}

\usepackage[hyperfootnotes=false,colorlinks=true,breaklinks]{hyperref}

\hypersetup{
       linkcolor={c1},  %internal links
       citecolor={c2},  %citations
       urlcolor={c3},   %external links
   }           

  % format chapitre

  \titleformat{\chapter}[display]{\bfseries\LARGE}{}{0pt}%
  {\raisebox{-5mm}[0pt][0pt]{%
   \begin{minipage}{20mm}
  \centering{\mdseries\footnotesize\textsc{chapitre}}\\ 
   [2pt]%
  \rule{10mm}{30mm}\hspace{-10mm}%
  \raisebox{25mm}{\parbox{10mm}{\centering\textcolor{white} 
  {\thechapter}}}%
  \end{minipage}}%
  \rule{\textwidth-20mm}{.4pt}\\%
  \hspace*{25mm}\MakeUppercase} [\vspace*{10mm}] 

 \definecolor{gray75}{gray}{0.75}
 \newcommand{\hsp}{\hspace{12pt}}
 \titleformat{name=\chapter, numberless}[hang] 
 {\Huge\bfseries}{\hsp\textcolor{gray75}{|}\hsp}{0pt} 
 {\Huge\bfseries} 

 % Page style
 \usepackage{fancyhdr}
 \pagestyle{fancy}
 \renewcommand{\chaptermark}[1] 
 {\markboth{\MakeUppercase{#1}}{}} % just the chapter title 
  without chapter1
  \renewcommand*{\sectionmark}[1]{\markright{#1}{}} %

  \fancyhead{}
  \fancyfoot{}

 \fancyhead[LO]{
 \bf{\thechapter} \space
 \makebox[0pt][r]{\space\smash{\vheadline}}%
 \space\footnotesize \bf \leftmark
}

\fancyhead[RE]{%
\footnotesize\bf\rightmark\space
\makebox[0pt][l]{\smash{\vheadline}\space}%
}
\fancyfoot[RE,RO]{\MakeUppercase{\chaptername}\ \thechapter\ 
{\vrule height 13pt width 2pt} \ \thepage }
\voffset-10mm
\renewcommand*\headrulewidth{0pt}
\newcommand*\vheadline{\textcolor{gray75}{\rule[-1pt]{3pt} 
 {1000pt}}}


   %========= CHAPTER HEADINGS

  \definecolor{ocre}{RGB}{52,177,201}
  \definecolor{ultramarine}{RGB}{0,45,97}
  \definecolor{mybluei}{RGB}{0,173,239}
  \definecolor{myblueii}{RGB}{63,200,244}
  \definecolor{myblueiii}{RGB}{199,234,253}
 \definecolor{chapnumberbg}{RGB}{26,40,105}
 \definecolor{chapname}{RGB}{100,117,158}

  \titleformat{\chapter}[display]
    {\normalfont}
   {}
   {0pt}
   {\stepcounter{chapshift}
   \begin{tikzpicture}
    \node[
    draw=chapname,

     rounded corners,
    outer sep=0pt,
    inner sep=6pt,
    rotate=90,
    line width=1pt,
    font=\Large\color{chapnumberbg}\bfseries
     ]
    (chapname) 
    {\chaptertitlename};
    \node[
    fill=chapnumberbg,
    minimum width=2cm,
    minimum height=2.3cm,
    rounded corners,
    anchor=west,
    font=\color{white}\fontsize{40}{48}\selectfont\bfseries
    ]
    at ([xshift=6pt]chapname.south)
    (chapnumber)
    {\thechapter};
    \node[
    anchor=west,
    text width=\textwidth-4cm,
    font=\bfseries\LARGE
    ] 
    at ([xshift=10pt]chapnumber.east)
    {#1};
    \fill[
    overlay,
    draw=none,
    line width=0pt,
    rounded corners=1pt,
    left color=chapnumberbg,
    right color=chapnumberbg!10
    ]
   ([yshift=-3pt]chapname.north west) rectangle ++ 
   (\textwidth,-3pt);  
   \end{tikzpicture}%
   }
   \titleformat{name=\chapter,numberless}[display]
    {\normalfont}
    {}
   {0pt}
  {%
  \begin{tikzpicture}
   \node[
    anchor=west,
    inner sep=0pt,
    outer sep=0pt,
    text width=\textwidth,
     font=\bfseries\LARGE
     ]
   (chaptitle) 
    {#1};
   \fill[
    overlay,
   draw=none,
    line width=0pt,
    rounded corners=1pt,
    left color=chapnumberbg,
    right color=chapnumberbg!10
    ]
    ([yshift=-3pt]chaptitle.south west) rectangle ++ 
    (\textwidth,-3pt);  
     \end{tikzpicture}%
    }



   \begin{document}
   \chapter*{Introduction générale}
   \lipsum[1-7]
    \chapter{Revue de littérature}
   \lipsum[1-7]
   \section{Définition}
   \lipsum[1-7]
   \chapter{Les hypothèses}
   \lipsum[1-7]
   \chapter*{Conslusion générale}
   \lipsum[1-7]
   \appendix
   \chapter{Annexes A}
   \lipsum[1-7]
   \chapter{Annexes B}
   \lipsum[1-7]

   \end{document}

enter image description here
enter image description here
enter image description here
enter image description here

Best Answer

You can create the headers and footers like this:

\documentclass[a4paper,12pt]{book}

\usepackage[top=3cm,bottom=3cm,left=2.5cm,right=2.5cm,headheight=22pt,headsep=25pt,heightrounded,footskip=1.5cm]{geometry}
\usepackage[table]{xcolor}
\usepackage{lipsum}

% Page style
\usepackage{fancyhdr}
\fancyhead{}
\fancyfoot{}
\colorlet{myfancycolor}{blue!60!black}
\makeatletter
\def\headrule{\color{myfancycolor}{\if@fancyplain\let\headrulewidth\plainheadrulewidth\fi
    \hrule\@height\headrulewidth\@width\headwidth
    \vskip-\headrulewidth}}
\makeatother

\fancypagestyle{mystyle}{
    \renewcommand*\headrulewidth{2pt}
    \fancyfoot[OR]{%
        \color{myfancycolor}%
        \rule[-6pt]{100pt}{20pt}%
        \hspace*{-90pt}%
        \begin{minipage}[b]{0.5cm}%
            \color{white}%
            \textsf{\thepage}%
        \end{minipage}%
    }%
    \fancyfoot[EL]{%
        \hspace*{-75pt}%
      \color{myfancycolor}%
      \rule[-6pt]{100pt}{20pt}%
      \hspace*{-25pt}%
        \begin{minipage}[b]{0.5cm}%
            \color{white}%
        \hfill%
        \textsf{\thepage}%
        \end{minipage}%
    }%
    \fancyhead[OR]{%
      \raisebox{0.5em}{\sffamily\nouppercase{\rightmark}}\space\color{myfancycolor}\rule{2em}{2em}\raisebox{0.5em}{\hspace{-2em}\color{white}\makebox[2em][c]{\textsf{\thechapter}}}%
      \vspace*{-0.5em}%
    }
    \fancyhead[EL]{%
      \color{myfancycolor}\rule{2em}{2em}\raisebox{0.5em}{\hspace{-2em}\color{white}\makebox[2em][c]{\textsf{\thechapter}}}\color{black}\raisebox{0.5em}{\space\sffamily\nouppercase{\rightmark}}%
      \vspace*{-0.5em}%
    }   
}

\fancypagestyle{plain}{%
    \renewcommand*\headrulewidth{0pt}
    \fancyhf{}%
    \fancyfoot[OR]{%
        \color{myfancycolor}%
      \rule[-6pt]{100pt}{20pt}%
        \hspace*{-90pt}%
      \begin{minipage}[b]{0.5cm}%
        \color{white}%
        \textsf{\thepage}%
      \end{minipage}%
    }%
    \fancyfoot[EL]{%
        \hspace*{-75pt}%
      \color{myfancycolor}%
      \rule[-6pt]{100pt}{20pt}%
      \hspace*{-25pt}%
        \begin{minipage}[b]{0.5cm}%
            \color{white}%
        \hfill%
        \textsf{\thepage}%
        \end{minipage}%
    }%
}   
\fancypagestyle{unnumbered}{%
    \fancyhead[OR]{%
    \raisebox{0.5em}{\sffamily\nouppercase{\rightmark}}\space\color{myfancycolor}\rule{2em}{2em}%
    \vspace*{-0.5em}%
    }
    \fancyhead[EL]{%
    \color{myfancycolor}\rule{2em}{2em}\color{black}\raisebox{0.5em}{\space\sffamily\nouppercase{\rightmark}}%
    \vspace*{-0.5em}%
    }
}

\pagestyle{mystyle}
\renewcommand{\chaptermark}[1]{\markboth{#1}{#1}}
\renewcommand*{\sectionmark}[1]{} %

\begin{document}

\pagestyle{unnumbered}
\chapter*{Introduction générale}
\markboth{Introduction générale}{Introduction générale}
\colorlet{myfancycolor}{blue!60!black}
\lipsum[1-7]
\chapter{Revue de littérature}
\pagestyle{mystyle}

\colorlet{myfancycolor}{red!60!black}
\lipsum[1-7]

\section{Définition}
\lipsum[1-7]

\chapter{Les hypothèses}
\colorlet{myfancycolor}{green!60!black}
\lipsum[1-7]

\chapter*{Conslusion générale}
\pagestyle{unnumbered}
\markboth{Conslusion générale}{Conslusion générale}
\colorlet{myfancycolor}{orange!60!black}
\lipsum[1-7]
\lipsum[1-7]

\appendix
\pagestyle{mystyle}

\chapter{Annexes A}
\pagestyle{fancy}
\colorlet{myfancycolor}{cyan!60!black}
\lipsum[1-7]


\chapter{Annexes B}
\colorlet{myfancycolor}{yellow!60!black}
\lipsum[1-7]

\end{document}

enter image description here