3

First fancyhdr is loaded to change the font of page number.

The following commands are used to change the font to sans serif:

\fancyhead[LO]{ \sffamily \thepage }
\fancyhead[RE]{ \sffamily \thepage }

However, in the first page of TOC, LOT, LOF and Chapter, the font is still serif.

Moreover, how to change the font of the page numbers (for chapters, sections, subsection, figures and tables) in TOC, LOT, LOF, including the Roman/roman number style for frontmatters as well?

Is the a simple command to change this font for the whole document (book, report or article)?

MWE:

\documentclass[12pt]{book}
\usepackage{kantlipsum}   
\usepackage{libertine}

\usepackage[]{fancyhdr}
\pagestyle{fancy}
\fancyhf{} % remove everything     
\fancyhead{} % clear all header fields  

\makeatletter
\renewcommand{\sectionmark}[1]{\markright{\thesection~~~#1}}
\renewcommand{\chaptermark}[1]{\markboth{\if@mainmatter\chaptername\\
 \thechapter~~~\fi#1}{}}
\makeatother

\newcommand{\vertline} {\smash{\rule[-.5ex]{1pt}{5in}}}  % head line
\fancyhead[LO]{ \sffamily  \thepage {} {} {}      {   \vertline   {} {}       \nouppercase \leftmark}  }
\fancyhead[RE]{ \sffamily { {  \nouppercase \rightmark {} {}   \vertline   {} {} {}  }\thepage } }  %
\renewcommand{\headrulewidth}{ 0.0 pt}

\newcommand{\myfig}{\begin{figure}\caption{A figure caption}\end{figure}}
\newcommand{\mytab}{\begin{table}\caption{A table caption}\end{table}}

\begin{document}
 \tableofcontents
 \listoffigures
 \listoftables
\chapter{Coo1} 
\kant[1]
\myfig\mytab\myfig\mytab\myfig\mytab
\section{Soo1}
 \kant[2-5]
\section{Soo2}
 \kant[6-9]

\chapter{Coo2}
\section{Soo3}
 \kant[11-6]
 \myfig\mytab\myfig\mytab\myfig\mytab
\section{Soo4}
 \kant[22-25]

\end{document}
2
  • 1
    Are you sure about the code for \fancyhead? It's quite a mess. For the specific problem, look on the site for \fancypagestyle and plain. For instance, tex.stackexchange.com/questions/18653/…
    – egreg
    Feb 8 '13 at 23:51
  • Concerning your code, you might be interested in \quad in place of {} {} {} {}
    – yo'
    Feb 9 '13 at 14:41
6

You can use \fancypagestyle:

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{} % remove everything     
\fancyhead{} % clear all header fields  

\makeatletter
\renewcommand{\sectionmark}[1]{\markright{\thesection\quad#1}}
\renewcommand{\chaptermark}[1]{\markboth{\if@mainmatter\chaptername\ \thechapter\quad\fi#1}{}}
\makeatother

\newcommand{\vertline}{\smash{\rule[-.5ex]{1pt}{5in}}}  % head line
\fancyhead[LO]{\sffamily\thepage\quad\vertline\quad\nouppercase\leftmark}
\fancyhead[RE]{\sffamily\nouppercase\rightmark\quad\vertline\quad\thepage}
\renewcommand{\headrulewidth}{0pt}
\setlength{\headheight}{14.5pt}

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

Instead of eye computed spacings, it's better to use known lengths, for instance \quad. Don't forget to set \headheight to a correct value, as recommended in the log file by fancyhdr

4

You have "discovered" that

in the first page of TOC, LOT, LOF and Chapter, the font is still serif

even though the fancy page style has been changed to use a sans-serif font for page numbers. This is the case because the first pages of chapters (and of chapter-like entities such as the ToC, LoT, and LoF) use the plain page style rather than the fancy style.

To modify the plain page style so that it uses a sans-serif font for page numbers, you could include the following code in your document's preamble:

\usepackage{etoolbox}
\makeatletter
\patchcmd{\ps@plain}{\thepage}{\sffamily\thepage}{}{}
\makeatother
\pagestyle{plain} % execute this command to load the new settings

Alternatively, since you're already using the fancyhdr package, you could proceed along the lines of @egreg's answer and use that package's \fancypagestyle{plain}{...} macro to modify the plain page style.

0

Based on egreg's response from Feb 29 '13, I believe this answers the question more concisely:

\usepackage{fancyhdr} % this goes in the preamble
% the next lines go in the body (i.e., between \begin{document} and \end{document}
\pagestyle{fancy}
\renewcommand{\headrule}{} % eliminate the default(?) ruled line in the header
\fancypagestyle{plain}{
    \fancyhead{}
    \fancyfoot[C]{\sffamily\thepage}
}
3
  • 1
    I'm not convinced, since you haven't defined what the fancy page style looks like. Instead, you've only redefined what the plain page style should look like. Moreover, the original request was for a sans-serif font, while ptm (or Times) sets a serif font.
    – Werner
    Feb 16 '17 at 16:11
  • This is more concise only in the sense that it will only work on the first pages of chapters etc., as opposed to setting things up for all pages. It is just a verbatim excerpt from egreg's code, copied with the spurious claim that it omits unnecessary frivolities.
    – cfr
    Feb 24 '17 at 1:02
  • My code edit should take care of your concern about the font. I came to this page originally because of the title. I was working on a simple article, with no TOC, LOT, or LOF. So, while I have not answered the entire question, I do answer a special case---and important special case, I think (i.e., the answer another user was looking for).
    – Ana Nimbus
    Feb 24 '17 at 1:03

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.