Recommended books on LaTeX:

Guide to LaTeX (4th Edition) Extensive and detailed companion with lots of examples written by the developers of LaTeX.

LaTeX Companion (2nd Edition) Popular introduction and reference for beginners.

The LaTeX Graphics Companion: Illustrating Documents with TeX and Postscript(R) Guidebook focused on including graphics and handling postscript fonts.

# LaTeX  for newbies

### Druckansicht

It is advisable to insert many comments into the source code, otherwise things might get confusing. Comments are visible only in the source code and will be ignored by the compiler.

Comments are inserted using the percent sign:

%
% figure x from book y, page z
%
\begin{figure}[htbp]
\centering
\fbox{
\includegraphics{filename}
}
\caption{title}
\label{labelname}
\end{figure}

If you want to insert a percent sign instead of a comment, you have to escape the percent sign. This is done by inserting a backslash (\) before the percent sign. Thereby the sign will be visible in the output file and the following text is not taken as a comment.
This is true for all charactes which have a special meaning for the compiler.

## formatting

### emphasizing text

Text is emphasized using the
\emph{text}

command.

The resulting font style depends on the context: if the text to be emphasized is surrounded by normal text, it will be italic. If the surrounding text is already italic, the emphasized text will be shown in the normal font.

Text is underlined using

\underline{text}

You may also chose a certain font style:

\textbf{text}


bold:

\textit{text}


serif:

\textsf{text}


sans-serif:

\texttt{text}


typewriter:

### font size

Font size is defined in relation to normal text using the following commands:
\tiny
\scriptsize
\footnotesize
\small
\normalsize
\large
\Large
\LARGE
\huge
\Huge

The text following these commands will be shown in the corrsponding size. A \normalsize-command has to be inserted in order to write in normal size again.

If you just want to write alter the size of a few words, you might want to use an alernative notation:

{\Large large text}
normal text


### verbatim

Text written insied the verbatim-environment will be shown just as it is written in the source code. Indention, linebreaks and spacing will be visible in the output file:
\begin{verbatim}
this
text
will
look just      like
that
in the    output
file.
\end{verbatim}


## paragraphs

Paragraphs are defined by inserting blank lines in the source file. Usually LaTeX will insert a linebreak and indent the beginning of the new paragraph in the output file. If you don't want to indent the first line of a new paragraph you have to insert the command
\parindent 0pt

in the head of the source file.

In order to define the height of a blank line you can use the command

\parskip 12pt

where you can use an arbitrary height.

### justification

Text is shown justified if no other justification command is given. In order to align the text to the left or to the right or to center it there are the following environments:
\begin{flushleft}
left-aligned
\end{flushleft}

\begin{flushright}
right-aligned
\end{flushright}

\begin{center}
centered
\end{center}


## sections

Sections are separated with the commands
\section{Titel}
\subsection{Titel}

and
\subsubsection{Titel}


If these commands are used, you can build the contents automatically: In order to insert the contents, simply insert

\tableofcontents

where you want it to appear in the output file.

## wraps

### linebreaks

You can force a linebreak using
\\

or
\newline


### pagebreaks

Pagebreaks are inserted using the
\newpage

command.

## lists

The are three different environments for lists: "itemize", "enumerate" and "description". The "itemize"-environment is used for simple lists, where the list items are just bulleted:
\begin{itemize}
\item item 1
\item item 2
\end{itemize}

If you want to use a different symbol as a bullet, you may define it as a parameter of the item-command:
\begin{itemize}
\item[-] Punkt 1 mit Strich
\item[*] Punkt 2 mit Stern
\end{itemize}

For numbered lists you use the "enumerate"-environment:
\begin{enumerate}
\item item 1
\item item 2
\end{enumerate}

You may also use the "description"-environment where the items are marked by a given word printed bold:
\begin{description}
\item[first] item 1
\item[second] item 2
\end{description}

The different list-environments can also be combined and nested:
\begin{description}

\item[first list] a few items

\begin{itemize}
\item subitem 1
\item subitem 2
\end{itemize}

\item[second list] more items

\begin{itemize}
\item subitem 1
\item subitem 2
\end{itemize}

\end{description}


## citing

### quotation marks

The leading quotation mark is "  ", the trailing quotation mark is " ' ".
In order to write double quotes, you use
text im double quotes''

for single quotes you write
text in single quotes'


### long quotations

For longer quotes or in order to emphasize important paragraphs, you use the "quote"-environment:
normal etxt
\begin{quote}
citation
\end{quote}

Text in the "quote"-environment is indented in the output file.

## displacement

Horizontal space is inserted using
\hspace{x cm}

and vertical space using
\vspace{x cm}

You may also use other units (pt,in,em..).

## cross references

You define a label using
\label{labelname}.

By inserting a reference to that label using
\ref{labelname},

LaTeX replaces the reference with the number of the corresponding section, subsection, figure or table.
\pageref{labelname}

is replaced by the page number where the corresping \label-command is found.

## bibliography

The biblioghraphy is generated using the thebibliography-environment:
\begin{thebibliography}{------}
...
\end{thebibliography}

The second parameter is optional and simply tells LaTeX, how many characters you want to use to label items in the bibliography (it doesn't matter, which characters you use in the parameter).

This is an example of how an entry in the bibliography might look like:

\bibitem[Bowie87]{bowie}
J. U. Bowie, R. L\"uthy and D. Eisenberg.
{\em A Method to Identify Protein Sequences That Fold
into a Known Three-Dimensional Structure}.
Science, 1991 (253), pp 164-170

The first parameter of the \bibitem-command is the label for the item which is shown in the output file. If the first parameter is omitted, the items will be numbered. The second parameter is used in the document to insert a reference to the entry in the bibliography. A reference to the entry shown in the example would look like this:
\cite{bowie}

this command will be replaced by [Bowie87] in the output file.

## inserting figures

In order to insert figures, the graphicx-package has to included in the preamble (before the \begin{document}-command) of your LaTeX-document:
\usepackage{graphicx}

Unfortunately only EPS-figures can be inserted withthe graphicx-package.
If you want to insert a figure, you will usually have to convert your graphics file to an EPS-file with a suitable program.
The simplest way of including a graphic looks like this:
\includegraphics{filename.eps}


If the image is not located in the same folder as the tex-file, you will have to specify the path relative to the tex-file.

If you want the image to appear in a different size, you can specifiy the size as a aprameter of the \includegraphics-command::
\includegraphics[width=4cm]{filename.eps}

This will scale the image to the width of 4 centimeters.
The \textwidth-command is useful if you don't want to specify an absolute size but rather want the actual size to depend on the text width:
\includegraphics[width=0.5\textwidth]{filename.eps}

will scale the image to half of the text width.

### The "figure"-environment

You use the figure-environment to let your image appear in a "floating" environment:
\begin{figure}
\includegraphics{filename.eps}
\label{labelname}
\end{figure}

Here \caption{...} defines the title of the figure which will appear beneath the figure. \label{..} defines the label which can be used inside the document in order to insert references to the figure:
The figure
\ref{labelname} on page \pageref{labelname} ..

The \label-command inside the \figure-envirnonment hast to appear just after the\caption-command.

### placing figures

If figures reside inside a \figure-environment, this will cause LaTeX to choose the actual location of the figure inside the document. There are different parameters for the placement strategy:

• h (here): Try to place the figure just where the command is located.
• t (top): Try to place the figure at the top of the page.
• b (bottom): Try to place the figure at the bottom of the page.
• p (float page): Try to place the figure on a page which contains only floating elements.
The order of these parameters doesn't matter since placement is always tried in the order h,t,b,p, if these parameters are present:

If no parameter is present, the default order istbp.

The command for a figure-environment might for example look like this:
\begin{figure}[htbp]
...
\end{figure}


### table of figures

A table of figures is inserted using the command
\listoffigures

The caption given in the \caption-command is also used in the list of figures.
If you want to use different captions, you may add a parameter to the \caption-command:
\caption[caption for listoffigures]{caption inside the document}


### figures with a border

There are two possibilities to place a border around figures: either only the figure itself is bordered or there is a border around the figure and its caption. You place a border around the figure using the \fbox-command.

Border around the figure:

\begin{figure}[htbp]
\centering
\fbox{
\includegraphics{filename}
}
\caption{caption}
\label{Labelname}
\end{figure}


Placing a border around the figure and its title is a little more tricky: You need to place the figure and the title in a \minipage-environment which is bordered again with the \fbox-command:

\begin{figure}[htbp]
\centering
\fbox{
\begin{minipage}{13 cm}
\includegraphics{filename}
\caption{caption}
\label{labelname}
\end{minipage}
}
\end{figure}

Unfortunately the width of the border can not be determined automatically. It has to be specified as a parameter of the \minipage-environment.

### side by side figures

You might want to place to figures side by side but use only one cpation. This is achieved by placing both figures in its own \minipage-environment which reside in the same \figure-environment.

if only one \caption-command us used, both figures will have a common title:

\begin{figure}[htbp]
\centering
\begin{minipage}[b]{5 cm}
\includegraphics{filename 1}
\end{minipage}
\begin{minipage}[b]{5 cm}
\includegraphics{filename 2}
\end{minipage}
\caption{common caption}
\label{Labelname}
\end{figure}


The first parameter of the \minipage-environment determines how both graphics are aligned to each other. b (bottom) aligns the bottom borders of the figures, t (top) aligns the top borders and c aligns the centers.

If you want distinct titles for the two figures you will only have to supply a \caption-command for both \minipage-environments:

\begin{figure}[htbp]
\centering
\begin{minipage}[b]{5 cm}
\includegraphics{filename 1}
\caption{caption 1}
\label{labelname 1}
\end{minipage}
\begin{minipage}[b]{5 cm}
\includegraphics{filename 2}
\caption{caption 2}
\label{labelname 2}
\end{minipage}
\end{figure}


If you want to have subfigures with distinct caption, you use the \subfigure-command:

\begin{figure}[htbp]
\centering
\subfigure[subcaption 1]{
\label{labelname 1}
\includegraphics{filename 1}
}
\subfigure[subcaption 2]{
\label{labelname 2}
\includegraphics{filename 2}
}
\caption{common caption}
\label{common label}
\end{figure}


Free counter