»

Dec 04

Complete control of LaTeX Headers and Footers

Hey all,

LaTeX is a great way for producing beautifully written math in PDFs for printing and online use.  Here is the code to have complete control over your headers and footers in LaTeX:

First, use the fancyhdr package (before “\begin{document}”):

\usepackage{fancyhdr}

Second, set the headers and footers (before “\begin{document}”, after the above code):

\pagestyle{fancyplain}
\lhead{\fancyplain{left head, start chapter}{left head, normal page}}
\chead{\fancyplain{center head, start chapter}{center head, normal page}}
\rhead{\fancyplain{right head, start chapter}{right head, normal page}}
\lfoot{\fancyplain{left foot, start chapter}{left foot, normal page}}
\cfoot{\fancyplain{center foot, start chapter}{center foot, normal page}}
\rfoot{\fancyplain{right foot, start chapter}{right foot, normal page}}

You can also use set the \headrulewidth and \footrulewidth

\renewcommand{\headrulewidth}{1pt}

\renewcommand{\footrulewidth}{3pt}

The best way to see what these produce is to compile a sample document! Here is one to use:

\documentclass{book}

\usepackage{fancyhdr}

\pagestyle{fancyplain}%
\lhead{\fancyplain{left head, start chapter}{left head, normal page}}
\chead{\fancyplain{center head, start chapter}{center head, normal page}}
\rhead{\fancyplain{right head, start chapter}{right head, normal page}}
\lfoot{\fancyplain{left foot, start chapter}{left foot, normal page}}
\cfoot{\fancyplain{center foot, start chapter}{center foot, normal page}}
\rfoot{\fancyplain{right foot, start chapter}{right foot, normal page}}

\renewcommand{\headrulewidth}{1pt}
\renewcommand{\footrulewidth}{3pt}

\begin{document}

\chapter{FirstChapter}

Blah blah blah this is text blah blah blah \newpage

blah blah blah this is text on the second page. Nice thick line
above the footer, eh?
\newpage

blah blah blah this is text on the third page, and the chapter is
about to end…

\chapter{SecondChapter}

blah blah blah this is text on the fifth page (the book
documentclass leaves a blank page to make sure the chapters start on
odd numbered pages).

\newpage

blah blah blah. Getting sick of the blah’s? Alright, I’m done.

\end{document}

Enjoy!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

What is 15 + 10 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)