LaTeX Guide

From Pirate Party Australia Wiki
Jump to navigation Jump to search

Starting a document

These commands will create a nicely formatted document.

\documentclass[a4paper,12pt]{article}
\usepackage[margin=1.25in]{geometry}
\begin{document}
Body text.
\end{document}

Although other parameters and document classes can be used, it is recommended to use A4 paper and 12pt as the defaults. Likewise, different parameters can be used to set margins, however 1.25 inches all around is a good default.

Packages

In the example above we used the package 'geometry' to adjust the page margins. Packages can be used to provide a variety of formatting options. Loading packages is simple. In the document header (before \begin{document} but after \documentclass) just insert:

\usepackage{package}

Some packages allow you to specify additional parameters. This will be shown in further examples below.

Measurements

Various parameters can be changed to increase or decrease sizes. Points, centimetres, millimetres and inches are the most common. Where appropriate you can use the following (without quotation marks):

"pt" (eg "16pt", "10pt")
"cm" (eg "1cm", "0.5cm")
"mm" (eg "5mm", "10mm")
"in" (eg "1.25in", "0.75in")

Working examples are provided in other sections.

Paragraph and line spacing

The default document settings will produce a document with paragraph indenting and no space between paragraphs. To change this so that there are spaces between paragraphs and no indents, load the 'parskip' package:

\usepackage{parskip}

You may want to increase the space between paragraphs further. You can do this using the following command (along with the parskip package):

\setlength{\parskip}{16pt}

"16pt" can be changed to any size (see the section on using measurements).

You may also want to increase the space between lines. The easiest way to do this is to use the 'setspace' package:

\usepackage{setspace}

Then insert, typically after the \begin{document} command, the following for one and a half spacing or double spacing respectively:

\onehalfspacing
\doublespacing

You can change the spacing within the document any time by using one of these commands. If you want to change from one and a half to double spacing, just use the appropriate command at the point you want it to change. If you want to return to single spacing, use the command:

\singlespacing

Basic text formatting

Quotation marks and apostrophes

Quotation marks are produced using grave accents (`) for the opening marks and the "typewriter" apostrophe (') for the closing marks. This is a very manual process, but gives specific control over the type of quotation mark/apostrophe used. For example:

`Hello world.'
``Hello world.''

You will want to use the typewriter apostrophe for regular apostrophes:

They're.

Regular quotation marks may not be correctly rendered, so be sure to use grave accents and typewriter apostrophes.

Bold and italics

Bold and italic text are produced using similar commands:

\textbf{Hello world.}
Hello world.
\textit{Hello world.}
Hello world.

Hyphens, en-dashes and em-dashes

The three types of hyphens/dashes you can use:

- regular hyphen
-- en-dash
--- em-dash

Extracts

Although usually you will want to quote only short sections, so quotation marks will suffice. If you want to extract longer sections, the 'quote' environment is useful:

\begin{quote}
Your extract here.
\end{quote}

Headings and titles

Headings

There are five main heading levels, from highest to lowest:

\section{Section Heading}
\subsection{Subsection Heading}
\subsubsection{Sub-subsection Heading}
\paragraph{Paragraph Heading}
\subparagraph{Subparagraph Heading}

\section, \subsection and \subsubsection will automatically produce numbered sections, eg 1, 1.1 and 1.1.1 respectively, based on their position within the documents. No manual numbering is necessary.

Changing the heading numbering

You can change the heading numbering to use numbering

No numbering

You can keep the section styling but have the numbering omitted by including an asterisk (*) after the command:

\section*{Section Heading}
\subsection*{Subsection Heading}
\subsubsection*{Sub-subsection Heading}

Note that numbering will simply skip these headings and that they will not appear in the table of contents. For example:

\section{Section A}
\section*{Section B}
\section{Section C}
\subsection{Subsection CA}
\subsection*{Subsection CB}
\subsection{Subsection CC}
\subsubsection{Sub-subsection CCA}
\subsubsection*{Sub-subsection CCB}
\subsubsection{Sub-subsection CCC}

will produce

1 Section A
Section B
2 Section C
2.1 Subsection CA
Subsection CB
2.2 Subsection CC
2.2.1 Sub-subsection CCA
Sub-subsection CCB
2.2.2 Sub-subsection CCC
Alphabetical & Roman numbering

Alphabetical section numbering is best achieved by using the 'sectsty' package. Include \usepackage{sectsty} in your document header (see the section on loading packages for more information).

Titles

Basic

Title page

Footnotes

Footnotes can be made by using the \footnote command. Other commands can be used in conjunction. For example:

\footnote{Matthew Rimmer, `The Empire of Cancer: Gene Patents and Cancer Voices', (2012--2013) 22(2) \textit{Journal of Law, Information and Science} 18, 44.}

Place the command directly where you want the footnote number to appear, without spaces. For example:

The quick brown fox\footnote{Citation.} jumps over the lazy dog.\footnote{Citation.}

Table of contents

Lists

There are three basic lists that can be made using three similar commands:

\begin{itemize} creates a bulleted list.
\begin{enumerate} creates a numbered list.
\begin{description} creates a descriptive list.

Remember to close each list with \end{itemize}, \end{enumerate} or \end{description}.

If you find these lists to be too spread out vertically (ie too much vertical space between items), load the package 'mdwlist' (\usepackage{mdwlist}) and use \begin{itemize*}, \begin{enumerate*} or \begin{description*} as appropriate. This will reduce the space and create tighter lists.

Use the command \item to insert items.

Here are some examples:

\begin{itemize}
\item This is an item.
\item This is a second item.
\item This is a final item.
\end{itemize}

This will produce:

  • This is an item.
  • This is a second item.
  • This is a final item.

You can nest lists easily (additional indentation in the code is for readability, and is encouraged for long lists). They can be the same or different types of lists:

\begin{itemize}
\item This is a bulleted item.
\item This is a second bulleted item.
\begin{itemize}
\item This is a nested bulleted item.
\item This is a second nested bulleted item.
\begin{itemize}
\item A list within a list within a list!
\begin{enumerate}
\item A numbered list within a list within a list within a list!
\end{enumerate}
\end{itemize}
\item This is a final nested bulleted item.
\end{itemize}
\item This is a final bulleted item.
end{itemize}

The description list allows for items to have a bold element and an accompanying description:

\begin{description}
\item[FTA] Free trade agreement
\item[KAFTA] Korea-Australia Free Trade Agreement
\item[JSCOT] Joint Standing Committee on Treaties
\end{description}

This will produce a result similar to:

FTA Free trade agreement

KAFTA Korea-Australia Free Trade Agreement

JSCOT Joint Standing Committee on Treaties

Please note that this will not be an aligned, table-like list. See the section on tables instead.