2

I am having a problem when adding \chapter and \section in the document. \markboth is not working when I compile it. I have got a link Why is \markboth not working?. But there is no solution about my problem. I have written the following code:

\documentclass[a4paper,12pt]{book}
\usepackage[vmargin=0.2cm,hmargin=1cm,head=16pt,includeheadfoot]{geometry}
\usepackage{fancyhdr,amsthm}
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{corollary}[theorem]{Corollary}
\fancyhead{}
\fancyfoot{}
\fancyhead[LE,RO]{\thepage}
\fancyhead[LO]{\slshape\rightmark}
\fancyhead[RE]{\slshape\leftmark}
\pagestyle{fancy}
\begin{document}
\markboth{Chapter}{Section}
\thispagestyle{empty}
\chapter{ Chapter}
\section{Section}

\begin{theorem}
 Theorem
\end{theorem}

\newpage
Second page
\newpage

Third page
\end{document}

This produces:

enter image description here
enter image description here enter image description here

But I want to get the following output:

enter image description here

enter image description here

enter image description here

How can I solve this problem ?

  • If it is not possible in this way , tell me alternative way. – Soumitra Sen Apr 28 '13 at 18:08
  • 1
    Not working isn't correct. You want a modification. This can be achieved by \renewcommand{\sectionmark}[1]{\markright{#1}} for section and \renewcommand{\chaptermark}[1]{\markboth{#1}{}}. For more details see the documentation with the examples of fancyhdr – Marco Daniel Apr 28 '13 at 18:11
  • Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. – jub0bs May 9 '13 at 12:41
2

You have to redefine \chaptermark and \sectionmark (after doing \pagestyle{fancy}). I have also reorganized a bit the code.

\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}

\begin{theorem}
 Theorem
\end{theorem}

\newpage
Second page
\newpage

Third page
\end{document}

enter image description here

enter image description here

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.