Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
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

2 Answers 2

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

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.