Thursday, December 17, 2009

Header/ Footer in Latex

Creating headers and footers in Latex can be done by using the package “fancyhdr”. This is a short introduction, showing the most important features of the package. If you know “fancyhdr” and are looking for something particular, refer to the fancyhdr-documentation.

First of all, you need to tell Latex to use the package:

\usepackage{fancyhdr}

and change the style from “plain” to “fancy”:

\pagestyle{fancy}

You will now the get the default fancy pagestyle which adds a line at the top of every page, except for some exceptions (title-page, abstract, new chapter in report).

Default fancyhdr page style:

Above the line, Latex will print headings:

Book/report

Left-hand side: section
Right- hand side: chapter
Note: if you use the optional documentclass argument “twoside”, Latex will alter the position of the section and chapter. (e.g. \documentclass[twoside]{report}, also introducing non-symmetric margins).

Article

For acticles, Latex will print the section only (chapters cannot be used with articles).
The footer only includes the page number which is centered by default.

Custom fancyhdr page style:

Even though fancyhdr has a default page style, you are free to define headers/footers yourself , which is not too difficult after all.

First you need to clear the default layout:

\fancyhead{}
\fancyfoot{}

There are seven letters you need to know before you can define your own header/footer:

E: Even page
O: Odd page
L: Left field
C: Center field
R: Right field
H: Header
F: Footer

Now you can start to define your own layout. The definitions are added before the document starts, usually after the “usepackages”:

\fancyhead[CO,CE]{---Draft---}
\fancyfoot[CO,CE]{Confidential}
\fancyfoot[RO, LE] {\thepage}

The decorative lines can be changed by increasing/decreasing their thickness (0pt means no line):

\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}

Note: After the fancyhdr-documentation, the default layout is produced by the following commands:

\fancyhead[LE,RO]{\slshape \rightmark}
\fancyhead[LO,RE]{\slshape \leftmark}
\fancyfoot[C]{\thepage}
\headrulewidth 0.4pt
\footrulewidth 0 pt

Reference: http://texblog.wordpress.com

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.

 
Free counter and web stats