# Getting to Grips with LaTeX

## Document Structure

This tutorial progresses significantly from the previous - very simplistic - tutorial. The goal is to produce a fairly basic article, of similar style to what a research paper would resemble. To achieve this efficiently, this tutorial focuses largely on document structure.

LaTeX practically forces you to declare structure within your documents. This is a good thing though. Because once LaTeX understands how you want your document organised, it will take care of all the tedious business of the layout and presentation for you. The separation of content and layout allows you to concentrate on the job at hand, i.e., communicating your research.

Before I begin to explain how to use various LaTeX commands, I believe it would be beneficial to see what the end result looks like first, so that we know from the beginning what the effects of our actions will be. Take a look at the output of this tutorial. Also, the LaTeX source is quite long, therefore, I shall only be using extracts throughout the tutorial. The source file is available here and at the end of this page.

### Preamble

If you recall from the previous tutorial, the preamble consists of everything from the start of the Latex source file until the \begin{document} command. It normally contains commands that affect the entire document.

% simple.tex - A simple article to illustrate document structure.

\documentclass{article}
\usepackage{times}

\begin{document}


The first line is a comment (as denoted by the % sign). The \documentclass command takes an argument, which is this case is article, because that's the type of document we want to produce. Other classes that exist are book, report, thesis etc. It is also possible to create your own, as is often done by journal publishers, who simply provide you with their own class file, which tells LaTeX how to format your content. But we'll be happy with the standard article class for now! \usepackage is an important command that tells LaTeX to utilise some external macros. In this instance, I specified times which means LaTeX will use the Postscript Times type 1 fonts, which look nicer :) And finally, the \begin{document}. This strictly isn't part of the preamble, but I'll put it here anyway, as it implies the end of the preamble by nature of stating that the document is now starting.

### Top Matter

At the beginning of most documents will be information about the document itself, such as the title and date, and also information about the authors, such as name, address, email etc. All of this type of information within LaTeX is collectively referred to as top matter. Although never explicitly specified, that is, there is no such \topmatter command, you are likely to encounter the term within LaTeX documentation.

An example:

\title{How to Structure a \LaTeX{} Document}
\author{Andrew Roberts\\
School of Computing,\\
University of Leeds,\\
Leeds,\\
United Kingdom,\\
LS2 1HE\\
\texttt{[email protected]}}
\date{\today}
\maketitle



The \title command is fairly obvious. Simply put the title you want between the curly braces. \author would also seems easy, until you notice that I've crammed in all sorts of other information along with the name. This is merely a common, albeit ungraceful, hack due to the basic article class. If you are provided with a class file from a publisher, or if you use the AMS article class (amsart), then you have a more logical approach to entering author information. In the meantime, you can see how the new line command (\\) has been used so that I could produce my address. My email address is at the end, and the \texttt commands formats the email address using a mono-spaced font. The \date command takes an argument to signify the date the document was written. I've used a built-in command called \today which, when processed by LaTeX, will be replaced with the current date. But you are free to put whatever you want as a date, in no set order. If braces are left empty, then the date is then omitted. Without \maketitle, the top matter would not appear in the document. So it is needed to commit your article attributes to paper.

### Abstract

As most research papers have an abstract, then there is a predefined commands for telling LaTeX which part of the content makes up the abstract. This should appear in its logical order, therefore, after the top matter, but before the main sections of the body.

\begin{abstract}
...
\end{abstract}


### Sectioning Commands

The commands for inserting sections are fairly intuitive. Of course, certain commands are appropriate to different document classes. For example, a book has chapters but a article doesn't. Here is an edited version of some of the structure commands in use from simple.tex.

\section{Introduction}
This section's content...

\section{Structure}
This section's content...

\subsection{Top Matter}
This subsection's content...

\subsubsection{Article Information}

This subsubsection's content...


As you can see, the commands are fairly intuitive. Notice that you do not need to specify section numbers. LaTeX will sort that out for you! Also, for sections, you do not need to markup which content belongs to a given block, using \begin and \end commands, for example.

Command Level
\part{part}-1
\chapter{chapter}0
\section{section}1
\subsection{subsection}2
\subsubsection{subsubsection}3
\paragraph{paragraph}4
\subparagraph{subparagraph}5

Numbering of the sections is performed automatically by LaTeX, so don't bother adding them explicitly, just insert the heading you want between the curly braces. If you don't want sections number, then add an asterisk (*) after the section command, but before the first curly brace, e.g., \section*{A Title Without Numbers}.

### The Bibliography

Any good research paper will have a whole list of references. In this example document, I have included one. If you look at the PDF version, then after the first instance of 'LaTeX' in the introduction, you should notice a numbered reference. And at the end of the document, you can see the full reference.

Fortunately, LaTeX has a slightly more intelligent approach to managing your references than the average word processor, like MS Word for example, where everything has to be inputted manually (unless you purchase a 3rd party add-on). There are two ways to insert your references into LaTeX: the first is to store them in an external file and then link them via a command to your current document, or secondly, embed them within the document itself. In this tutorial, I shall quickly cover the latter. Although, the former will be covered in depth in a future tutorial, as it is by far the most efficient and flexible.

There are two stages to setting up your bibliography/references in a document. The first is to set up a bibliography environment, which is where you provide LaTeX with the details of the references. The second is the actual citation of your references within your document.

The following code was used in creating the bibliography environment for the document in this tutorial. It is located immediately after the last line of the document content, but before the \end{document} command.

\begin{thebibliography}{9}

\bibitem{lamport94}
Leslie Lamport,
\emph{\LaTeX: A Document Preparation System}.
2nd Edition,
1994.

\end{thebibliography}


OK, so what is going on here? The first thing to notice is the establishment of the environment. thebibliography is a keyword that LaTeX recognises as everything between the begin and end tags as being data for the bibliography. The optional argument which I supplied after the begin statement is telling LaTeX how wide the item label will be when printed. Note however, that it is not a literal parameter, i.e the number 9 in this case, but a text width. Therefore, I am effectively telling LaTeX that I will only need reference labels of one character in width, which means no more than nine references in total. If you want more than ten, then input a two-digit number, such as '99' which permits less than 100 references.

Next is the actual reference entry itself. This is prefixed with the \bibitem{cite_key} command. The cite_key is should be a unique identifier for that particular reference, and is often some sort of mnemonic consisting of any sequence of letters, numbers and punctuation symbols (although not a comma). I often use the surname of the first author, followed by the last two digits of the year (hence lamport94). If that author has produced more than one reference for a given year, then I add letters after, 'a', 'b', etc. But, you should do whatever works for you. Everything after the key is the reference itself. You need to type it as you want it to be presented. I have put the different parts of the reference, such as author, title, etc., on different lines for readability. These lines are ignored by LaTeX. I wanted the title to be in italics, so I used the \emph{} command to achieve this.

To actually cite a given document is very easy. Goto the point where you want the citation to appear, and use the following: \cite{cite_key}, where the cite_key is that of the bibitem you wish to cite. When LaTeX processes the document, the citation will be cross-referenced with the bibitems and replaced with the appropriate number citation. The advantage here, once again, is that LaTeX looks after the numbering for you. If it was totally manual, then adding or removing a reference can be a real chore, as you would have to re-number all the citations by hand.

Of course, it may be your preference to use a different referencing system, such as Harvard, instead of the default numerical. This will be covered in the future, in the mean time, why not try to experiment with the Natbib package.

### Extras

You will find examples of using lists, as well as a table in the sample document I produced for this tutorial. Tables can be rather tricky, and so I intend to write a tutorial just on this topic in the future. However, please take time to inspect the source code yourself to see if you can also see how these extras were made, now that you are beginning to understand the mechanics of the LaTeX system.

Files: simple.tex | simple.pdf

Last updated: February 22, 2012

« Back to LaTeX tutorials.