[Tex/LaTex] Header of the thesis

fancyhdrheader-footer

I used the following for the header, as I have \chapter*. It works great, the only problem is with bibliography where the header shows as ''Chapter4. BIBLIOGRAPHY'' as chapter 4 is the last chapter.

\documentclass[12pt,a4paper,oneside]{book}

\usepackage{fancyhdr}
\pagestyle{fancy}

\renewcommand{\chaptermark}[1]{\markboth{#1}{}}

\fancyhf{} % clear the headers
\fancyhead[R]{%
   % We want italics
   \itshape
   % The chapter number only if it's greater than 0
   \ifnum\value{chapter}>0 \chaptername\ \thechapter. \fi
   % The chapter title
   \leftmark}
\fancyfoot[C]{\thepage}

\fancypagestyle{plain}{
  \renewcommand{\headrulewidth}{0pt}
  \fancyhf{}
  \fancyfoot[C]{\thepage}
}

\setlength{\headheight}{14.5pt}

\usepackage{kantlipsum} % for the mock text

\begin{document}

\frontmatter

\chapter{Introduction}

\kant

\mainmatter

\chapter*{Another introduction}
\chaptermark{Another introduction}

\kant

\chapter{Title}

\kant

\end{document}

Best Answer

Simply define a new style bib

\fancypagestyle{bib}{%
\fancyhf{}
\fancyhead[R]{%
   % We want italics
   \itshape
   % The chapter title
   Bibliography}
}

and issue

\pagestyle{bib}

just before your bibliography.

MWE:

\documentclass[12pt,a4paper,oneside]{book}

\usepackage{fancyhdr}
\pagestyle{fancy}

\renewcommand{\chaptermark}[1]{\markboth{#1}{}}

\fancyhf{} % clear the headers
\fancyhead[R]{%
   % We want italics
   \itshape
   % The chapter number only if it's greater than 0
   \ifnum\value{chapter}>0 \chaptername\ \thechapter. \fi
   % The chapter title
   \leftmark}
\fancyfoot[C]{\thepage}

\fancypagestyle{bib}{%
\fancyhf{}
\fancyhead[R]{%
   % We want italics
   \itshape
   % The chapter title
   Bibliography}
}

\setlength{\headheight}{14.5pt}

\usepackage{kantlipsum} % for the mock text

\begin{document}

\frontmatter

\chapter{Introduction}

\kant

\mainmatter

\chapter*{Another introduction}
\chaptermark{Another introduction}

\kant

\chapter{Title}

\kant

\backmatter
\nocite{*}
\pagestyle{bib}
\bibliographystyle{plain}
\bibliography{test}

\end{document} 

Output:

enter image description here


Some remarks:

  • If your bibliography isn't in the \backmatter issue

    \clearpage
    

    before it.

  • I've removed the plain page style:

    \fancypagestyle{plain}{
      \renewcommand{\headrulewidth}{0pt}
      \fancyhf{}
      \fancyfoot[C]{\thepage}
    } 
    

    since it doesn't changes the default one.

Related Question