8

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 ?

7

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}
  • Great! This is working well. – Soumitra Sen May 2 '13 at 10:45
  • 1
    @SoumitraSen Accepting answers (and upvoting them) is the preferred way to say thank you on this site. Further, it helps keep the site clean (knowing which of the questions still need to be answered and which ones have already been answered satisfactorily). Please accept answers and help keep the site clean. – kan May 2 '13 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.