texblog

Changing the font size in fancyhdr

The default header with fancyhdr for a book (two-sided by default) displays the chapter at the inner side (left odd, right even) and the section title at the outer side (left even, right odd). For long chapter and/or section titles, the two may overlap.

There are several possible workarounds to solve this issue. One may

 

Using the optional argument for a shorter title

Similar to captions, headings take an alternative argument for a shorter title used in the table of contents as well as for the header.

\chapter[Short chapter title]{This is a very long chapter title}
\section[Short section title]{A somewhat long section title}

 

Changing header/footer font size

In order to change the font size, we redefine the default fancyhdr layout. Below is a minimal working example for the book documentclass. It works similarly for report and article.

\documentclass[11pt]{book}
\usepackage{fancyhdr, blindtext}
\newcommand{\changefont}{%
	\fontsize{9}{11}\selectfont
}
\fancyhf{}
\fancyhead[LE,RO]{\changefont \slshape \rightmark} %section
\fancyhead[RE,LO]{\changefont \slshape \leftmark} %chapter
\fancyfoot[C]{\changefont \thepage} %footer
\pagestyle{fancy}
\begin{document}
\tableofcontents
\chapter{A long chapter title}
\section{A long section title}
\Blindtext\Blindtext
\end{document}

Basically, I copied the code for the default layout from the package documentation and added the font size modification to size 9pt (with baselineskip 11pt). I created a macro \changefont to save some typing.

\newcommand{\changefont}{%
	\fontsize{9}{11}\selectfont
}

The example uses \slshape for slanted as in the fancy header’s default layout.

See this article for more details on how to change the font size in LaTeX.

Drop me a comment below or see the package documentation for more details.

For longer titles you may need a combination of both, an alternative title and a smaller font size.

 

Display chapter and section alternately

In this example we choose to display the section title on even pages on the left (LE) and the chapter title on odd pages on the right (RO). Further, for illustration purposes, we place the page number on the inner side of the header.

\documentclass[11pt]{book}
\usepackage{fancyhdr, blindtext}
\fancyhf{}
\fancyhead[LE]{\slshape \rightmark} %section
\fancyhead[RE]{\thepage}
\fancyhead[RO]{\slshape \leftmark} % chapter
\fancyhead[LO]{\thepage}
\pagestyle{fancy}
\begin{document}
\tableofcontents
\chapter{A long chapter title}
\section{A long section title}
\Blindtext\Blindtext
\end{document}

See my post on that topic and the fancyhdr package documentation for more details.

Exit mobile version