9

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.

2
  • Perhaps this question is helpful, or this one. Mar 24, 2012 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).
    – jshlke
    Mar 24, 2012 at 11:04

1 Answer 1

14

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]{}
2
  • Also, thanks for not just posting the solution but for explaining it well!
    – jshlke
    Mar 24, 2012 at 16:41
  • Looks easy, but what I am getting for a book class is: ! LaTeX Error: Command \partmark undefined. Any clue?
    – Andrestand
    Jun 27 at 18:22

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.