[Tex/LaTex] Want to get ‘book name, and ‘chapter name, in header

fancyhdrheader-footer

I asked a question to get 'chapter name' and 'section' in the header in the following link : \markboth is not working when using \chapter and \section. Now I have decided to replace the section name with 'book name' in the header in the same question posted earlier. I have tried to change it in the following way :

\documentclass[a4paper,12pt]{book}

\usepackage[vmargin=0.2cm,hmargin=1cm,head=16pt,includeheadfoot]{geometry}

\usepackage{fancyhdr,amsthm}

\pagestyle{fancy}
% We don't want chapter and section numbers    
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
%\renewcommand{\sectionmark}[1]{\markright{#1}}

\fancyhead{}
\fancyfoot{}
\fancyhead[LE,RO]{\thepage}
\fancyhead[LO]{\slshape\rightmark}
\fancyhead[RE]{\slshape\leftmark}

\theoremstyle{plain}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{corollary}[theorem]{Corollary}

\begin{document}

\chapter{Chapter}
\section{Section}
\markboth{book name}{section name}
\begin{theorem}
 Theorem
\end{theorem}

\newpage
Second page
\newpage

Third page
\end{document}

But 'book name' is not appearing in the header. What is the required command to have 'book name' in odd pages and 'chapter name' in even pages ?

Best Answer

Issuing explicit \markboth commands in the document body is a last resource.

Just tell fancyhdr what you want; \leftmark is just a (probably badly chosen) name, it "contains" the last thing has been specified as the first argument in a \markboth command, which is usually implicit in \chapter (more precisely, \chapter does \chaptermark which in turn executes \markboth).

\pagestyle{fancy}
% We don't want chapter and section numbers
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}

\fancyhead{}
\fancyfoot{}
\fancyhead[LE,RO]{\thepage}
\fancyhead[LO]{\slshape Book Title} % odd pages: book title
\fancyhead[RE]{\slshape\leftmark}   % even pages: chapter title

\theoremstyle{plain}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{corollary}[theorem]{Corollary}