Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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 ?

share|improve this question

1 Answer 1

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}
share|improve this answer
    
Great! This is working well. –  Soumitra Sen May 2 '13 at 10:45
    
@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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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