4

I am using fancyhdr in my report and a selected font. The page number font is correct on the pages when a new chapter starts, but it is reverts to some other font on the other pages. I think these problematic pages are the ones defined by fancy? I cannot understand why fancy gets the header font correct, but messes up with the footer page number font. I have searched a lot but cannot find the solution. Please see my MWE:

\documentclass[a4paper,12pt]{report}
\renewcommand{\familydefault}{\sfdefault}
\usepackage{fancyhdr}
\begin{document}
\pagestyle{fancy}
\chapter{Test}
The page number font for the page where a chapter starts is correct.
\newpage
\section{Wrong font}
The page number font on this page is wrong.
\end{document}

Am I defining my document font correctly? If so, how can I fix the page numbering font for my fancy pages so that they are the same as the document font?

This problem occurs in a large report, so if there is a solution that is unlikely to clash with anything else it would be better.

3
  • The first page is using the plain page style as it is a chapter title page. By default fancyhdr does not touch plain unless you explicitly as it to. Just for fun, I switched to the memoir class (give it the openany class option and it will behave like report), it has its own build in header/footer interface. In memoir there is no issues with the fonts.
    – daleif
    Jul 21, 2017 at 7:40
  • 1
    Actually, in the fancyhdr souece you'll find the problem, the code actually says \fancyfoot[c]{\rmfamily\thepage} as the default footer for the fancy style (the \rmfamily overwrites your setting). You'd probably have to tell fancyhdr what footer you want. That would be described in the fancyhdr manual.
    – daleif
    Jul 21, 2017 at 7:45
  • Thanks @daleif. If you can post the answer and it works, I'll mark it as correct. Jul 21, 2017 at 10:37

2 Answers 2

6

If we look in fancyhdr.sty we find

\fancyfoot[c]{\rmfamily\thepage} % page number

as the default code for the header of the fancy page style. Note the \rmfamily. It overrides your sans serif setting.

You can probably just add

\fancyfoot[c]{\thepage}

or

\fancyfoot[c]{\sffamily\thepage}

to your preamble and it should work.

As mentioned, it might be easier in the long run to switch to a more high level class, like memoir or something from the KOMA bundle. Then you don't need so many packages to get the layout you want. Note for example that memoir has its own well integrated page style system, so fancyhdr should not be used with that class.

3
  • 1
    Thank you! fancyfoot[c]{\thepage} did the trick! I cannot use memoir as it does not seem to be compatible with my use of \part{} sectioning. Jul 21, 2017 at 11:06
  • @NicoleAndrew please show me an example of that. memoir supports \part just fine.
    – daleif
    Jul 21, 2017 at 11:15
  • @NicoleAndrew memoir not only supports \parts but also \books. Jul 21, 2017 at 18:08
1

I just want to point titleps, which comes with titlesec, does not have this problem:

\documentclass[a4paper,12pt]{report}
\renewcommand{\familydefault}{\sfdefault}
\usepackage{titleps}
\newpagestyle{myps}{%
\headrule
\sethead{\itshape\thesection. \MakeUppercase{\sectiontitle}}%
{}%
{\itshape\MakeUppercase{\chaptername~\thechapter.\enspace\chaptertitle}}
\setfoot{}{\thepage}{}}

\usepackage{lipsum}

\begin{document}

\pagestyle{myps}
\chapter{Test}

The page number font for the page where a chapter starts is correct.
\lipsum[1-5]

\section{Right font} The page number font on this page is right.

\end{document}

enter image description here

7
  • Thanks @Bernard! This causes some kind of compatibility problem in the huge report structure I'm using... I get this error from inside : Command \headrule already defined. \newcommand\headrule{\setheadrule{.4\p@}}. I don't know nearly enough about LaTeX, but was hoping there might be a less 'intrusive' answer. Jul 21, 2017 at 10:32
  • Probably you still load fancyhdr? If that's the case, you can't load both, as they tackle the same problem. Note titleps is easier to customise than fancyhdr, as it doesn't use the marks system by default.
    – Bernard
    Jul 21, 2017 at 10:38
  • 1
    I cannot find any code explicitly adding fancyhdr, I used grep on the whole folder, but found it in the main files log file: main.log:(/usr/share/texlive/texmf-dist/tex/latex/fancyhdr/fancyhdr.sty Can fancyhdr be added by other packages somehow? Jul 21, 2017 at 10:43
  • Yes, it may happen: either a package, or by your .cls file. Could you post them (or a link to)?
    – Bernard
    Jul 21, 2017 at 10:51
  • Is it possible that fancyhdr is automatically included in the report class that I am using? I cannot use memoir, as suggested in the other comments because I use \part dividers in my report that memoir doesn't seem to support. Jul 21, 2017 at 11:02

You must log in to answer this question.

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