...change the page style (numbers/header/footer)?

Changing the page style goes a long way towards making your document look a little bit nicer. In $latex \LaTeX$ this is accomplished with the \pagestyle command but, as so often is the case, other packages get created to give you more options and more control over your document. You need to know that the top part of the document, above the body of the text, is called the header. The bottom part of the document, below the body of the text, is called the footer.

$latex \LaTeX$ comes with 4 standard pagestyles:

\pagestyle{empty}  results in no headers or footers. Since the page number is, by default, placed in the footer, this command removes the page number.

\pagestyle{plain}   results in no headers and a footer with a centered page number.

\pagestyle{headings} a header with the name of the chapter/subsection and the page number.

\pagestyle{myheadings} no footer and the page numbering is in the header (along with other information).

But if you are interested in controlling the information in the header and footer  then you should use the fancyhdr package. So:

  1. If you want nothing on the page but the text you type, use \pagestyle{empty}
  2. If you want your text and the page number, do nothing (that's what you'll get by default.
  3. Anything else, use the fancyhdr package. This will give you good control over the information in the header and footer.

To use the fancyhdr package you'll need to put

\usepackage{fancyhdr}
\pagestyle{fancy}

in the preamble of your document. The fancyhdr package gives you control over the left, center and right of the header and the left, center, and right of the footer. The left header and footer are left justified, the center header and footer are centered and the right header and footer are right justified. The information that goes in those 6 specific spots is specified by using some/all of the following commands in the preamble:

  • \lhead{} controls the left header
  • \chead{} controls the center header
  • \rhead{} controls the right header
  • \lfoot{} controls the left footer
  • \cfoot{} controls the center footer
  • \rfoot{} controls the right footer

So, for example, \lhead{My Awesome Book} in the preamble will put My Awesome Book on the left header; i.e., in the upper lefthand corner of the page. If you don't want the page number in the center of the footer (done by default) then put \cfoot{} in the preamble. To move the page numbering to another part of the header or footer, you'll need to know that the page number of your document is stored in the variable \thepage. If you want to move print the page number in the upper right hand corner of the page (right header) then put \rhead{\thepage} in the preamble.

With respect to the page numbering, the numbers are in Arabic numerals. If you want to change this you can insert one of the following into the preamble:

\pagenumbering{roman} lower case Roman numerals for page numbers

\pagenumbering{Roman} upper case Roman numerals for page numbers

\pagenumbering{alph} lower case letters for page numbers

\pagenumbering{Alph} upper case letters for page numbers

\pagenumbering{roman} lower case Roman numerals for page numbers

For completeness, \pagenumbering{arabic} gives Arabic numerals for page numbers. This would be useful in you want to switch page styles within a single document.

The fancyhdr package also lets you include a decorative line in the header and footer as well as control the its thickness. This is done with the following commands

\renewcommand{\headrulewidth}{0pt} % no line in the header
\renewcommand{\footrulewidth}{2pt} % a 2 point thick line for the footer

There's a lot of information here to absorb here so I've posted a sample tex file and its output. The example illustrates how to put include a picture into the header/footer. I've chosen a picture of Tux, the Linux mascot (from the Open Clip Art Library) and used Gimp to convert it from SVG to JPEG. As I mentioned here, Inkscape is a possibility. You can, of course, put your own JPEG file into the document: just change the name in the tex document and make sure the picture is in the same folder as your tex document.

PageStyle (tex...you'll need to supply a picture for this to compile)      PageStyle (PDF)

Here's a screenshot of the output using Gummi; I set some crazy margins so you could see the page number in the right header and the picture in the left footer.

PageStyle

Finally, the fancyhdr package gives you even more control over your document than what's been mentioned here such as multi-line headers and footers, different headers/footers depending on whether the page is even or odd, and more; see the fancyhdr documentation at CTAN.

 

Leave a Reply

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

AlphaOmega Captcha Classica  –  Enter Security Code