Tuesday, 31 January 2012

My simple LaTeX thesis template

I'm a minimalist so when the time came to finally write my thesis in LaTeX, I wasn't going to spend time fussing about making sure my chapter numbers came out in Cambridge blue. (Apparently, the navy blue default in that package was oh-so-Oxford...) I started, as all good research does, by searching for what others had done before. Some departments provide a thesis class; some host classes used by previous students; and some offer nothing at all. The closest thing in Cambridge is a thesis class at the Department of Engineering (CUED). I found this template, and several others from previous students, overly complicated so I elected to build my own file from the ground up.

I put together a very simple thesis file that covers the basics. In this post, I'll show you what I've done, what it does and how you can change it if you want.


My material is divided into "front" matter, like an abstract and plagiarism declaration; "main" matter, which is the thesis content itself; and "back" matter, which is here just the bibliography but could include an index. The three-way division led me to start with the default book class. For margins, I use the geometry package. It's a powerful package but I only use it to set the margins (1in) and the binding offset (0.5in). My bibliography is compiled using BibTeX so I call the natbib package too with my favourite options: author, year style wtih round brackets. The bare bones of my thesis file is thus

\input{dec} % Declaration
\input{abs} % Abstract
\input{ch1} % Chapter 1
\input{ch2} % Chapter 2
\input{ch3} % Chapter 3
\input{apA} % Appendix A

That's it! That's all you really need for a LaTeX thesis. But I'm sure you'd like to add a bit more functionality and a light personal touch.

Extra features

There are three extra functional packages I call. First and foremost is graphicx for figures. Next, it's nice to hyperlink cross-references in the text so I summon hyperref. I took this straight from the CUED thesis so I'm not sure if all of the options are necessary. I've also omitted my colour choices for brevity but they're all listed in the documentation. Third, for some extra table of contents goodness, I invoke tocbibind. My actual thesis thus has the three extra preamble lines

\usepackage[breaklinks = true, linktocpage, pagebackref,
colorlinks = true, hyperindex = true, hyperfigures] {hyperref}

Some style

Finally, we can add some personal style. The main thing is to change the chapter headings. There are a number of choices here. I personally use the quotchap package with a grey number. This gives me space for quotes and a nice chapter heading in only one package.


Example chapter heading with quotchap. Taken from the official example.

The other option I'd recommend is the fncychap package, which contains about 7 chapter styles you might try and some of which I have seen used here in Cambridge.

The seven chapter styles available in fncychap. Taken from the official examples.

In any case, I set the front matter bits as numberless chapters and use a quote block to increase the margins there.


If you want the front matter to appear in the contents, add after \chapter*{} a line like


where chapter indicates the insertion level and Declaration is the text that is added.

I'm in the UK and I subscribe to the style guidelines of Monthly Notices of the Royal Astronomical Society so I use their bibliography style, I use A4 paper and flush my equations to the left. The last two points are accomplished with the [a4paper,fleqn] options in the book class. The bibliography style is invoked with 


where mn2e replaces plainnat.

The last thing to customize is the title page. Mine is a hardcoded mess that works for me so I don't see any point putting it up. I encourage you to play around with some title.tex to put your final stamp on the front.
Throw that all together and you'll have just about everything in my thesis that isn't actual content. This is a quick and simple file which I encourage other people to build on. But it's here to prove that choosing a layout is actually quite straightforward so you can get down to actually writing.
Any suggestions from your thesis files? Further simple additions that add to the final product or things that needn't be here? Let me know in the comments.

Wednesday, 25 January 2012

The wonders of arcsinh

Do you sometimes need to plot a number that has large magnitude but can be positive or negative? I do and I have a trick to do it: instead of plotting x, I plot arcsinhx/2/log10. For positive x, it gives log10x; for negative x, -log10-x. It's quite accurate for x10 and is linear across zero. Pretty much exactly what I need!

Our friend, arcsinh, is the purple curve. The approximating logarithms are in red and blue.

To see why this works, it helps to know that


For x0,


For x0,

logx+sqrtx2+1logx+x1+1/2x2 log1/2x=-log-2x.