[[latex]]
 

LaTeX

LaTeX is a type-setting software suite that allows you to produce exceptionally elegant documents, letters, posters and presentations. The beauty of LaTeX is that is separates the content from the style, freeing you from the hassle of formatting the content as you go.

Overview

This is by no means a comprehensive guide to LaTeX, its simply a collection of notes, tips and tricks that I've used over the years and find useful. I would highly recommend the book Guide to LaTeX by Kopka & Daly as an indispensible reference. I've two copies, one for work and one at home and use it all the time. The same information can be found on the net, but in my experience a lot of the LaTeX pages are hard to find.

Tables

Spanning Rows and Columns

Spanning rows and columns is exceptionally easy. You need to include the multirow package in the preamble of your document (\usepackage{multirow}) and to span columns you simply.

\begin{table}[!ht]
\begin{center}
\begin{tabular}{lccc}
  \hline
                                & \multicolumn{3}{c}{A centralised header} \\
                                & Column 1 & Column 2 & Column 3        \\ 
  \hline
\multirow{2}{*}{A two-row span} & Cell 1   & Cell 2   & Cell 3          \\
                                & Cell 4   & Cell 5   & Cell 6          \\
  \hline
\end{tabular}
\end{center}
\end{table}

This will produce the following table

A centralised header
A two-row span Cell 1 Cell 2 Cell 3
Cell 4 Cell 5 Cell 6

(You'll note that I've been unable to find how to do row-spanning in doku!)

Longtables

Sometimes you wish to have a table that is too big (in length) to fit onto one page. In such instances the longtable package can be used to spread tables over multiple pages. You should load the package in your pre-amble with \usepackage{longtable}. You then define two sets of first rows, one that goes at the very top of the first table, and one that appears at the top of each table on subsequent pages, and similarly for the end of tables, one is specified for the bottom of all pages, and a final row for the very last page.

A basic template is provided below for three columns…

\begin{longtable}{lcr}
  \caption[Longtable]{Demonstrating the ''\longtable''\label{ltable}} \\
  \hline
  Left & Center & Right \\
  \hline \endfirsthead
  \caption[]{\emph{Continued}} \\
  \hline
  Left & Center & Right \\
  \hline \endhead
  \multicolumn{3}{r}{\emph{Continued on next page\dots}} \\
  \endfoot
  \hline \endlastfoot
\end{longtable}

Special Characters

LaTeX has a plethora of special characters available. Some are provided in the stock installation, whilst others are provided as part of individual packages. The ultimate reference for all symbols is The Comprehensive LaTeX Symbol Guide. I've detailed below a number of symbols that I have had recourse to use on a regular basis.

Symbol Code
\checkmark
\male
\female

Verbatim Text

Including examples of code is (as with many other things) straight-forward in LaTeX, you simply use the verbatim environment and encapsulate your code within the \begin{verbatim} and \end{verbatim}. For small sections of in-line code that you wish to include simply use the \verb|your text| alternative.

A different approach, particularly useful if you wish to use colour in your code, is to use the alltt tags to encapsulate your code…

\begin{alltt}
  \textcolor{red}{/* Set up the system                                                 */}
  capture log c
  label drop _all
  clear
  set more off
  version 10.1
  set mem 600m
  ...
\end{alltt}

Headers and Footers

LaTeX has sections for headers and footers on each page of a document. The defaults for these are simple and straightforward, but sometimes you may want more fancy headers and footers. Fortunately there is the fancyhdr package that allows fine tuning and customisation of the headers and footers.

In the header of your document you most load the package, declare that the fancy pagestyle is to be used and then simply fill in the text that you want in the left (\l), center (\c) or right (\r) of the header (head) or footer (foot)

\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{}
\chead{}
\rhead{}
\lfoot{}
\cfoot{}
\rfoot{}

Text boxes

To place a box around a section of text simply use the following code

\ovalbox{%
\begin{minipage}{0.9\textwidth}
...
\end{minipage}}

Alternative Documents

As well as books, reports and theses LaTeX can be used to generate slides, posters and letters. The sections below detail the packages and approaches I've used to generate these documents.

Slides

The Prosper package is simple and ideal for creating slide-shows as PDFs.

Posters

Posters can be prepared relatively easily using LaTeX (all I need to do is find the tutorial/howto pages I used when I first did this!).

Letters

Writing letters in LaTeX is very straightforward use the following template and type your letter contents (including tables, images etc.) in-between the \opening{} and closing{} tags, then compile your document as you would normally.

\documentclass[a4paper]{letter}
\address{1st Line of your Address \\ 2nd Line \\ 3rd Line \\ 4th Line \\ etc.}
\name{Your Name}
\signature{Your title as you would like it to appear at the bottom of the letter}
\begin{document}
\begin{letter}{1st Line of Recipients Address \\ 2nd Line \\ 3rd Line \\ 4th Line \\ etc. }
\opening{Dear Somebody,}
 
\closing{Yours sincerely}
\end{letter}
\end{document}

BibTex

Including references in technical reports to work and methods that you cite is crucial to producing self-contained informative papers, reports and posters. Bibliographies and references are handled using BibTex.

I use two methods for managing my BibTex references. I keep and manage a local copy on my system using the excellent Pybliographer although this is now essentially just a regularly downloaded/updated version of the references I keep at CiteULike. My references at CiteULike can be viewed here (General, mainly genetics) and here (specifically related to cancer and epidemiology).

A large number of BibTex styles for various journals (primarily focused on biological journals) is available here.

Links

 
latex.txt · Last modified: 2009/06/29 21:37 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki