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 am trying to use fancyhdr to set the part no. and name on my left pages and chapter no and name on the right pages.

My document is

\documentclass[11pt,a4paper,twoside,openright,bibliography=totocnumbered]{scrbook} 

I use the following code (which looks wrong and doesn't work too well):

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead[RE]{\leftmark}
\fancyhead[LO]{\rightmark}

\renewcommand{\partmark}[1]{\markboth% 
  {\color[gray]{.0}\thepart. #1}{}}

\renewcommand{\chaptermark}[1]{\markright%
  {\color[gray]{.0}\thechapter.\ #1}}

The effect is: I get the part alright but the chapter only makes it to the head as long as I haven't used a section. Once there's a section in my text, it seems to overrule the chapter.

share|improve this question
    
Perhaps this question is helpful, or this one. –  Thorsten Donig Mar 24 '12 at 11:00
    
Hi Thorsten, Thanks for the links. However, I had looked at both questions before posting and they couldn't solve my problem (which is with chapter rather than part). –  Seul Mar 24 '12 at 11:04

1 Answer 1

up vote 11 down vote accepted

You have to redefine \sectionmark to do nothing (and also to clear the fields):

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[RE]{\leftmark}
\fancyhead[LO]{\rightmark}
\fancyfoot[RO,LE]{\thepage}

\renewcommand{\partmark}[1]{\markboth
  {\color[gray]{.0}\thepart. #1}{}}

\renewcommand{\chaptermark}[1]{\markright
  {\color[gray]{.0}\thechapter.\ #1}}

\renewcommand{\sectionmark}[1]{}

However, I would put formatting instructions into \fancyhead and not in the \markright and \markboth commands:

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[RE]{\color[gray]{0}\leftmark}
\fancyhead[LO]{\color[gray]{0}\rightmark}
\fancyfoot[RO,LE]{\thepage}

\renewcommand{\partmark}[1]{\markboth{\thepart. #1}{}}
\renewcommand{\chaptermark}[1]{\markright{\thechapter.\ #1}}
\renewcommand{\sectionmark}[1]{}
share|improve this answer
    
Thanks so much, works just like I wished now. –  Seul Mar 24 '12 at 12:01
    
Also, thanks for not just posting the solution but for explaining it well! –  Seul Mar 24 '12 at 16:41

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.