3

As part of a recent project, I want to have even and odd pagenumbering, as the document is to be printed double sided. I have added even and odd pagenumbering, which works as intended, however on every page containing a chapter or part header, the page number is centered rather than on the left or right.

The documentclass is:enter image description here

\documentclass[12pt, a4paper,openright]{book}

And the headers and footers are:

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[lo,le]{\nouppercase{\rightmark}}
\fancyfoot[LE,RO]{\thepage}
5

Quoting from p. 7 of the user guide of the fancyhdr package:

Some LaTeX commands, like \chapter, use the \thispagestyle command to automatically switch to the plain page style, thus ignoring the page style currently in effect. To customize even such pages you must redefine the plain pagestyle. As we indicated before you could do this by defining the \ps@plain command, but fancyhdr gives you an easier way with the \fancypagestyle command. This command can be used to redefine existing pagestyles (like plain) or to define new ones, e.g. if part of your document is to use a different pagestyle. This command has two parameters: one is the name of the pagestyle to be defined, the second consists of commands that change the headers and/or footers, i.e. fancyhead etc. Also allowed are changes to \headrulewidth and \footrulewidth.

I take it that you want the page numbering on \part and \chapter pages to be "fancy" as well, minus the header portion. If that's the case, the following code should work for you.

\documentclass[12pt, a4paper,openright]{book}
\usepackage{lipsum} % for filler text
\usepackage[danish]{babel} % is 'danish' correct?

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[lo,le]{\nouppercase{\rightmark}}
\fancyfoot[LE,RO]{\thepage}

\fancypagestyle{plain}{% % <-- this is new
  \fancyhf{} 
  \fancyfoot[LE,RO]{\thepage} % same placement as with page style "fancy"
  \renewcommand{\headrulewidth}{0pt}}

\begin{document}
\part{Kontekstuelt}
\chapter{One}
\section{Introduction} % to make "\rightmark" non-empty
\lipsum[1-10]
\end{document}

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.