[Tex/LaTex] fancyhdr: How get part on even and chapter on odd pages

chaptersdouble-sidedfancyhdrheader-footerparts

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.

Best Answer

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]{}