LaTeX Basics

Miki Havlíčková

February 9, 2004

1 Processing and printing

”Code” for your document should sit in a file name.tex To process this document on Athena, type add newtex; latex2e name.tex This will create a few files, in particular name.dvi To view your processed file, type xdvi name.dvi To print this file, type dvips -Pprinter name.dvi To convert your file into a postscript document, type dvips -o name.ps name.dvi

2 Document outline

Your document will look something like this:

\documentclass[options]{document class}
\author{your name}
\title{whatever it is}
\date{put a date here or write '\today' to put today's date automatically}
Here go other special commands that affect the outline of your document.
\begin{document}
\maketitle
Here goes the text of your document.
\end{document}

Document class

There are four classes: article, report, book and letter. They differ slightly in the way they are preformatted; we will worry about article for now. Its options are things such as font size and type (default 12pt, Times), or twoside if you want your article to be double-sided (affects things such as headings, page margins etc.). For example, you can have

\documentclass[12pt, helvetica, twoside]{article}

Title

This should be pretty self-explanatory; note that you have to put the \maketitle command after \begin{document} in order for your author, title and date to actually appear in the document. These commands are optional; you can omit any one of the three, or just skip the title entirely.

Outline commands in preamble

You can change pagemargins, spacing, and other such things here; see references for details. Of these the most immediately useful is spacing; to change it put

\renewcommand{\baselinestretch}{factor, like 2 for double-spaced}

Text

The article class comes with sections, subsections, and subsubsections. To begin say a section, type

\section{title of your section (can be left empty)}

These are numbered in the way you’d expect; to omit the numbering, put an asterisk after section, that is \section*{}.

To force a new line, put \\ at the desired break place. To start a new paragraph, leave a blank line. LaTeX will ignore all extra space left in between words; you can use the command \vspace{1cm} to insert extra space (in cm, mm, pt, or pretty much anything you want). The command \hspace{5mm} accomplishes the same for vertical spacing.

Footnotes

These are generated by the command

\footnote{text}

They are numbered, incrementing throughout the article (i.e. do not reset with each section, or anything of the sort).

Special charaters

You can print some command characters by putting a backslash in front of them, like \& which will produce &. Characters from foreign languages can also be printed; see references for how to do that.

3 Text formatting

• To temporarily change your font size, write

     {\fontsize Text goes here}

Possible font sizes are

tiny scriptsize footnotesize small normal large Large LARGE huge

Huge.

• To change character of your font, write

     {\command Text goes here}

The main possibilities for command are em, bf, sl rm (the last one produces the usual font).

• To center your text, write

     \begin{center}
     Text goes here
     \end{center}

4 Lists

The main list formats are enumerate, itemize and description. The command is

\begin{enumerate, itemize or description}
\item[name goes here in case of description]
\item[again a name for description]
\end{enumerate, itemize or description}

The first numbers the entries, second bullets them (as in the previous section), and third puts name in bold followed by the text.

5 Tables

Table is constructed with

\begin{tabular}{column descriptions go here}
rows of table
\end{tabular}

The column descriptions have on letter for each column, which can be r, c or l, indicating where you want the text to be inside the column (right, center or left). Optionally you can put one or multiple | in between the letters, which will separate the columns by a vertical line. For example, you can put {||c|r||} to make a table with two columns separated by a vertical line with double line on the outside, where first and second columnts have respectively center and right indentations of the text.

Lines of the table have the format

first column entry  &  second column entry  \\\hline

The entries are separated by & (and can be left empty). The \hline command is optional, and will draw a horizontal line below the row (if you want a double or any multiple line, just repeat \hline\hline etc.)

For example, to produce this table:

Day  Class Time
Monday  18.01 10-11
Tuesday  14.01 12-1

Wednesday

Thursday  14.01 12-1
Friday  18.01 10-11

I typed the following:

\begin{tabular}{||l||c|c||}
\hline\hline
Day & Class & Time \\\hline\hline
Monday & 18.01 & 10-11 \\\hline
Tuesday & 14.01 & 12-1 \\\hline
Wednesday & & \\\hline
Thursday & 14.01 & 12-1 \\\hline
Friday & 18.01 & 10-11 \\\hline\hline
\end{tabular}

6 References

This document, as well as its .tex version, is on the class website, along links to various helpful LaTeX sites. You can also pick up an Athena minicourse package in the Copy Tech, or look at any of various LaTeX books; I like ”A Guide to LATEX 2e” by Helmut Kopka and Patrick W. Daly.