1

Have I missed an instruction for specifying where the document class scrbook places the page number on the first page of each chapter of a book?


In a book with multiple chapters, involving diverse and complex formatting, I am using scrbook, for its support of \multiplefootmarker. I am also using fancyhdr, in order to control header content.

With scrbook and fancyhdr coexisting, I have a problem getting page numbers to appear centered on the first page of each chapter. fancyhdr centers page numbers as desired after the first page of a chapter. But it seems that scrbook defaults to placing page numbers on the bottom right of each chapter's first page, and that seems to override fancyhdr's \fancyfoot command. A MWE follows (actual use of \multiplefootmarker isn't needed to illustrate the problem).


\documentclass[12pt]{scrbook} % needed for use of \multiplefootmarker (not shown)

% Fancy *headers* are only needed on pages after first of chapter.
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead[RO]{Right header only needed on pages after chapter's first.}
\fancyhead[LE]{Left header only needed on pages after chapter's first.}
\fancyhead[RE,LO]{}

% But page number should be centered at bottom of every page.
\fancyfoot[C]{\thepage}

% For MWE content
\usepackage{lipsum}

\title{Book Title}

\begin{document}
  \maketitle
  \chapter{Chapter Title}
    \markboth{Right Header Text}{Left Header Text}
    \lipsum[1-12]
  \chapter{Another Chapter Title}
    \markboth{Right Header Text}{Left Header Text}
    \lipsum[1-12]
\end{document}

Edit: Following @Ulrike_Fisher's comment, I added a command

\newcommand\headrulecontrol{
  \fancypagestyle{plain}{
    \renewcommand{\headrulewidth}{0pt}\fancyhf{}\cfoot{\thepage}}
  \renewcommand{\headrulewidth}{1pt}
  }

and then modified each chapter to, for example:

  \chapter{Chapter Title}
    \markboth{Right Header Text}{Left Header Text}
    \headrulecontrol
    \lipsum[1-12]

This works fine — page numbers are centered but there is no page-head rule on the first page of a chapter.

3
  • 1
    \fancypagestyle{plain}{\fancyhf{}\cfoot{\thepage}} see the documentation of fancyhdr. Dec 7, 2016 at 18:31
  • Thank you. Indeed, fancyfoot doesn't seem to be needed at all in the presence of \fancypagestyle. But, interestingly, a horizontal line now appears at the top of the first page of each chapter. I see that I can eliminate it with \renewcommand{\headrulewidth}{0pt}, but do I then need to restore an explicit head rule after the first page? Dec 7, 2016 at 18:42
  • Oh, I see how to use \renewcommand for that a second time right after using fancyhf. Thanks again. Dec 7, 2016 at 18:57

1 Answer 1

1

As @Ulrike mentioned you have to redefine the plain style in the preamble:

\fancypagestyle{plain}{
    \fancyhf{}% remove all entries in header and footer
    \fancyfoot[C]{\thepage}% centred page numbers in footer
    \renewcommand{\headrulewidth}{0pt}% no headsepline on plain pages
}

Setting \headrulewidth to 0pt for page style plain affects only the headrule on plain pages.

Example:

\documentclass[12pt]{scrbook} % needed for use of \multiplefootmarker (not shown)

% Fancy *headers* are only needed on pages after first of chapter.
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[RO]{\rightmark}
\fancyhead[LE]{\leftmark}

% But page number should be centered at bottom of every page.
\fancyfoot[C]{\thepage}

\fancypagestyle{plain}{
    \fancyhf{}
    \fancyfoot[C]{\thepage}
    \renewcommand{\headrulewidth}{0pt}
}

\usepackage{lipsum}% For MWE content
\title{Book Title}

\begin{document}
  \maketitle
  \chapter{Chapter Title}
    \markboth{Left Header Text}{Right Header Text}
    \lipsum[1-12]
  \chapter{Another Chapter Title}
    \markboth{Left Header Text}{Right Header Text}
    \lipsum[1-12]
\end{document}

Note that I have changed the header entries. On left pages (even page numbers) \leftmark is now used and on right pages (odd page numbers) \rightmark. So your \markboth commands can change the header entries. But the \chapter command sets marks too.


Maybe you want to use package scrlayer-scrpage which is part of the KOMA-Script bundle:

\documentclass[12pt]{scrbook} % needed for use of \multiplefootmarker (not shown)

\usepackage[
    headsepline,
    manualmark% because of your manual usage of \markboth
]{scrlayer-scrpage}
\clearpairofpagestyles
%\rohead{Right header only needed on pages after chapter's first.}
%\lehead{Left header only needed on pages after chapter's first.}
\ohead{\headmark}
\cfoot*{\pagemark}
\addtokomafont{pageheadfoot}{\normalfont}

\usepackage{lipsum} %For MWE content

\title{Book Title}
\begin{document}
  \maketitle
  \chapter{Chapter Title}
    \markboth{Left Header Text}{Right Header Text}
    \lipsum[1-12]
  \chapter{Another Chapter Title}
    \markboth{Left Header Text}{Right Header Text}
    \lipsum[1-12]
\end{document}

But do you really want to set the marks manually? If \chapter and \section should set the marks automatically, change option manualmark to automark and remove your \markboth commands.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .