1

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

Siham
  • 55
  • For very fancy headers or footers, I use everypage and tikzpagenodes. See https://tex.stackexchange.com/questions/276358/text-on-background-image-footer-and-header OTOH, this approach ignores pagestyle changes. – John Kormylo Sep 14 '18 at 14:47
  • thank you but it doesn't help coz i dont' want images in my footer and header or may be i didn't get it :( and i actually struggle with tikz – Siham Sep 14 '18 at 14:54
  • I'm sorry if this is not intersting i'm a newbie so i thought i will found help here. thank you anyways – Siham Sep 14 '18 at 15:07
  • and i think you just being selfish and i'm sorry to say that but it's not about getting intersting topics it's about helping other people and guidding them because not everyone is good as you and trying to get more interesting problems . I really didn't like your last reponse ps sorry for my english i'm not a native speaker i'm learning – Siham Sep 14 '18 at 15:19
  • Please make a minimal working example (MWE) including \begin{document}, \end{document} and the necessary sections etc. so that we have something to start with. Currently we would have to first put work into making your code compile before we could start to solve your problem. Also accusing us to being "selfish" might not be the best strategy to convince people to use their free time without any charge to solve your problems... – samcarter_is_at_topanswers.xyz Sep 16 '18 at 13:10
  • thank you smacrter. for the selfish response i'm sorry but i the person resposne was not good eitheri think he delet it and i'm sorry for that – Siham Sep 16 '18 at 13:25
  • @samcarter I did edit my question with a begin and end document thak you so much – Siham Sep 16 '18 at 13:37
  • 1
    @samcarter Do you konw someone who does latex services as a job? like not free service i was looking buthere in my country we don't have a specialists in latex? sorry if my question seems not related to the topic i wanted to ask you in private message but i did not know how. – Siham Sep 16 '18 at 13:41
  • 1
    @Siham See https://tug.org/consultants.html for a list of tex consultants – samcarter_is_at_topanswers.xyz Sep 16 '18 at 14:12
  • @Siham Please note that your code does not compile. Packages are missing, others are missing optional arguments, missing comment characters and empty lines at the wrong places cause errors during compilation. – samcarter_is_at_topanswers.xyz Sep 16 '18 at 14:17
  • THANk you yeah i know i have a lot of issues :( do you konw how to get diffent color for each chapter header?? can you see my new post thank you so much for your time aand kidness – Siham Sep 16 '18 at 14:21

1 Answers1

3

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

  • I want the footer to be in always in the right; DO i hav eto specify that it is one side document or its gonna make more errors because i didn't work with it in the first place – Siham Sep 16 '18 at 14:30
  • @Siham If you want them all on the same side, use oneside as document class option. – samcarter_is_at_topanswers.xyz Sep 16 '18 at 14:42
  • i have an hrule even in the page where is the title!! how can i do with unumbered chapters coz its look not good :( do you have a suggestion for that coz i can't suitch to a numebered chapter because introduction conclusion are not considered chapters in our thesis faculty regulations – Siham Sep 16 '18 at 14:55
  • I used \markboth{Introduction}{} to display the unumbered chapters in header but i still have number 0 in the little box :( – Siham Sep 16 '18 at 17:45
  • I really spendt all the evening without figuring a solution to my issue I think i will give up :( – Siham Sep 16 '18 at 17:47
  • TOO MUCH PRESSURE FOR ME :( – Siham Sep 16 '18 at 17:47
  • @Siham Please see my edited answer – samcarter_is_at_topanswers.xyz Sep 16 '18 at 19:31
  • Thank you do much for your time and effort. I had a lot of warning useless E in fancy ....i did specefy oneside but i got a lot of warning :( – Siham Sep 16 '18 at 20:50
  • Really you made my day and make me happy you are so kind thank you so much. FOR your the previous response i did find a solution for unumbered chapter i specify {if num \value {chapter}>0\thechapter\fi} and it worked – Siham Sep 16 '18 at 20:54
  • @Siham Please check of your workaround also works for your conslusion section. This should have the number of the previous chapter and not 0 – samcarter_is_at_topanswers.xyz Sep 16 '18 at 20:56
  • The warnings for E tell you that it is not necessary to specify both cases if you use a oneside document. I'll leave them in my answer because they might be useful for future users, but you can remove them. – samcarter_is_at_topanswers.xyz Sep 16 '18 at 20:57
  • If i leave the code at it is ,it doesnt have any side effect coz i'm afraid to coz some problems by moving them? Or i just delet ER or OL??? Coz they got different values?? – Siham Sep 16 '18 at 21:09
  • Fot tje conclusion i got conclusion with no number in the box thank you so muchh even the TOC and references i have what i really wanted you are my savior thank you thank you – Siham Sep 16 '18 at 21:10