Fancy headers in LaTeX books

First in a series of notes on book formating under LaTeX. This is the header.tex file that defines the format for the headers and footers for each page. It’s pretty standard, as described in e.g. the Page Layout chapter of the wikibook on LaTeX. The only trick is taken from Mark Schenk’s page about his MSc Thesis: this piece of code makes empty pages (typically, the ones on even pages across the first pages of some chapters) completely and immaculately empty.

\usepackage{fancyhdr}
\setlength{\headheight}{15.2pt}
\pagestyle{fancy}

% http://www.markschenk.com/tensegrity/latexexplanation.html
% Code for creating empty pages
% No headers on empty pages before new chapter
\makeatletter
\def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else
\hbox{}
\thispagestyle{plain}
\newpage
\if@twocolumn\hbox{}\newpage\fi\fi\fi}
\makeatother \clearpage{\pagestyle{plain}\cleardoublepage}

%\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
%\renewcommand{\sectionmark}[1]{\markright{#1}{}}

\renewcommand{\chaptermark}[1]%
{\markboth{\chaptername\ \thechapter.\ #1}{}}
\renewcommand{\sectionmark}[1]%
{\markright{\S \thesection.\ #1}{}}

\fancyhf{}

\fancyfoot[LE,RO]{\thepage}

\fancyhead[LE]{\textit{\nouppercase{\leftmark}}}
\fancyhead[RO]{\textit{\nouppercase{\rightmark}}}

%\fancypagestyle{plain}{ %
%\fancyhf{} % remove everything
%\renewcommand{\headrulewidth}{0pt} % remove lines as well
%\renewcommand{\footrulewidth}{0pt}}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s