# Robin's Blog

## My LaTeX preamble

Since I started my PhD I have forced myself to use LaTeX for all of the documents that I write (yes, absolutely everything), and this has really helped me get to grips with how to do things in LaTeX. Overall I have been very impressed – my documents now look really professional, and LaTeX actually works really well and isn’t that hard to get to grips with.

I thought I’d write this post to explain the various packages that I always load in my LaTeX preamble. I’ve often been meaning to put all of my preamble into a style file so that I can load it in one line, but I’ve never quite got round to it. Maybe I’ll write another blog post about this when I get round to doing it…

Anyway, without further ado, below is my standard LaTeX preamble, with brief comments explaining the packages I’ve loaded. Below the code I go into further detail about the packages I use most.

\documentclass[12pt]{article}

% Pretty much all of the ams maths packages
\usepackage{amsmath,amsthm,amssymb,amsfonts}

% Allows you to manipulate the page a bit
\usepackage[a4paper]{geometry}

% Pulls the page out a bit - makes it look better (in my opinion)
\usepackage{a4wide}

% Removes paragraph indentation (not needed most of the time now)
\usepackage{parskip}

% Allows inclusion of graphics easily and configurably
\usepackage{graphicx}

% Provides ways to make nice looking tables
\usepackage{booktabs}

% Allows you to rotate tables and figures
\usepackage{rotating}

% Allows shading of table cells
\usepackage{colortbl}
% Define a simple command to use at the start of a table row to make it have a shaded background
\newcommand{\gray}{\rowcolor[gray]{.9}}

\usepackage{textcomp}

% Provides commands to make subfigures (figures with (a), (b) and (c))
\usepackage{subfigure}

% Typesets URLs sensibly - with tt font, clickable in PDFs, and not breaking across lines
\usepackage{url}

% Makes references hyperlinks in PDF output
\usepackage{hyperref}

% Provides ways to include syntax-highlighted source code
\usepackage{listings}
\lstset{frame=single, basicstyle=\ttfamily}

% Provides Harvard-style referencing
\usepackage{natbib}
\bibpunct{(}{)}{;}{a}{,}{,}

\usepackage{color}
\usepackage{xcolor}

% Simple command I defined to allow me to mark TODO items in red
\newcommand{\todo}[1] {\textbf{\textcolor{red}{#1}}}

% Allows fancy stuff in the page header
\usepackage{fancyhdr}
\pagestyle{fancy}

% Vastly improves the standard formatting of captions
\usepackage[margin=10pt,font=small,labelfont=bf, labelsep=endash]{caption}

% Standard title, author etc.
\title{COMP6024\\Model Specification based on \citet{Telfer:2010}}
\author{Robin Wilson\\ID: 21985588}
\date{}
% Put text on the left-hand and right-hand side of the header


So, which of those are most important, and why do I use them:

• amsmath – This is a package by the American Mathematical Society for typesetting mathematics sensibly. I’m not a mathematician, but I often have to include maths in my documents. Nearly all of the tutorials you read on the internet for doing maths in LaTeX will be for amsmath, and it generally gives very good results (and every possibly mathematical symbol/feature you will ever need).
• parskip – I hate indented paragraphs in wordprocessed documents – I’m sure there are various typsetting rules against doing it. Anyway, this removes all paragraph indentation without screwing anything else up!
• booktabs, rotating and colortbl – These provide everything I need to produce good quality tables. Booktabs gives me a number of different options for alignment, as well as providing \toprule and \bottomrule which give thicker lines for the top and bottom of tables. Rotating allows you to produce sideways tables and figures when they won’t fit properly on a portrait page, and. Colortbl allows shading of tables cells. I’ve defined my own command here because I often want to shade a table cell with a light gray. This command (\gray) is simply replaced with \rowcolor[gray]{.9}.
• subfigure – This gives a really simple way to include various image files as one figure, labelling each one as (a), (b), (c), with different captions. Simple, but works really well.
• url – Again, this does one very simple thing very well: it typsets URLs sensibly. Simply wrap the url in \url{} and it typesets it in typewriter font, makes it into a clickable link (in PDF files) and stops it breaking over lines
• caption – This is one of the most important packages in my list. It allows you to style the captions produced for tables and figures to make them actually look different from the rest of the text. This is very important to help guide the reader around the page. The way I call the package is \usepackage[margin=10pt,font=small,labelfont=bf, labelsep=endash]{caption}, and this makes the caption indented, in a smaller font, with the label (eg. Figure 10) in bold and separated from the rest of the caption by a dash. Again, this really tidies up the appearance of documents.
• fancyhdr – This lets you put useful things in the header of the document. For example, for my university work I put my name on the right-hand side of the header, and the course code on the left-hand side of the header. The simple \lhead and \rhead commands do that for me easily.

I haven’t been through all of my packages above, but the rest of them are fairly easily understandable. In my view, they are the really key packages for almost any type of LaTeX document.

1. You don’t need the url package; hyperref provides the same functionality (except with a link, which url doesn’t do on its own), and since it’s loaded after url, it’s overwriting what url does anyway.

2. Oh, and you only need xcolor, not both color and xcolor.

Hi,
Nice stuff! For my own PhD thesis, I used this header:

The result is (in my opinion) very nice, mostly thanks to the wonderful Garamond font family. You can see it here: http://tel.archives-ouvertes.fr/tel-00348586/en