Questa è una vecchia versione del documento!


LaTex syntax quick references

[ Home ] [ Back ]

Comments

% this is a comment

Basic document structure

\documentclass[options]{class type}
...
...


\begin{document}
...
...
\end{document}

Preamble

The portion of code within \documentclass and \begin{document} statements.

Available document classes:

  • article (chapters are not supported)
  • report
  • book (two-side document by default)
  • letter

Basic class options:

\documentclass[a4paper,11pt]{class type}

The default font sizing is 10pt, but you can also specify 11pt or 12pt.

Core document

The code within \begin{document} and \end{document}.

Extensions (packages)

\usepackage[options]{package name}

Basic formatting syntax

LaTex supports bold, italic etc.

LaTex supports \textbf{bold}, \textit{italic} etc. 

You can also combine all these,

You can also \textit{\textbf{combine} all these}

Note that \textit{} and \emph{} produce the same italic output.

Sectioning

A document can be divided using chapters, sections, subsections, sub-subsections and paragraphs.

\chapter{name}
\section{name}
\subsection{name}
\subsubsection{name}

New paragraphs are automatically created by leaving an empty line.

Breaks

\newline
\newpage
\clearpage

The \clearpage command is similar to \newpage, but forces LaTex to print all folating tables and pictures before the page break.

\vfill

The \vfill fill command produces a rubber length which can stretch or shrink vertically. It is equivalent to a blank line followed by \vspace\fill.

Spacing

Vertical spacing:

\vspace{5mm}

Horizontal spacing:

\hspace{8cm}

Usually you will specify spaces in cm or mm, but other typographic units exist.

Alignment

\begin{center}
...
\end{center}
\begin{flushright}
...
...
\end{flushright}
\begin{flushleft}
...
...
\end{flushleft}

Pictures

First you need to declare the package in your preamble:

\usepackage{graphicx}

Then you could use this code in order to insert an image in the same path of your file .tex (otherwise you have to specificate the whole path and not only the name of your picture):

\begin{figure}[options]
 \centering
 \includegraphics[angle=-90, scale=0.80,keepaspectratio=true]{pipe.jpg}
 \caption{Ceci n'est pas une pipe - This is not a pipe (Magritte).}
 \label{fig: pipe}
\end{figure}

Environment figure options:

  • h - here
  • t - top of the page
  • b - bottom of the page
  • p - extra page
  • ! - force positioning

includegraphics main options:

  • angle=[+/- degree values]
  • scale=[value] (i.e. 0.80 means that you are resizing your picture at the 80%)
  • keepaspectratio=[true/false]

You can refer to a picture in your text by using the \ref{labelcontents}, i.e.:

\ref{fig: pipe}

See also:

Tables

Math formulas

Graphs

Coding

Non-formatted text

Verbatim environment permits to insert large sections of preformated text in a LaTeX file (for example, also symbols like '%', '&', '#' and much more):

\begin{verbatim}
Roses are #FF0000 & violets are #0101DF
sugar is sweet and so are you. 
\end{verbatim}

Feynman diagrams

Table of contents

A table of contents (TOC) is automatically created using the command

\tableofcontents

Note that two consecutive compilation are required to update the table of contents

Other similar commands are \listoftables and \listoffigures which produce a list of tables (LOT) and a list of figures (LOF) respectively.

Numerical references

To create references inside your text, use the \cite{refLabel} command wherever you want an external reference to something (books, papers, Web sites, etc.). It is a good practice to use the surname of the first author followed by the last two digits of the year of publication. Each reference will be numbered and each citation will correspond to the number.

Then you can build a bibliography with the LaTex built-in environment thebibliography,

\begin{thebibliography}{n}
   \bibitem[label]{refKey} Author(s), \emph{Work title}, detailed reference coordinates
   ...
   ...
\end{thebibliography}

Here {n} is the maximum number of expected references in the list, usually {100} works fine. This parameter is mandatory (compile error otherwise).

By default the name of the page will be Bibliography. If you want to change it in References use

\renewcommand{\bibname}{References}  %  print "References" instead of "Bibliography"
\begin{thebibliography}{n}
   ...
   ...
\end{thebibliography}

Furthermore, by default the bibliography is not automatically added to the table of contents.

\clearpage
\addcontentslin{toc}{chapter}{References}
\renewcommand{\bibname}{References}
\begin{thebibliography}{100}
   ...
   ...
\end{thebibliography}

Each item of the bibliography is referenced with a number within square brackets. You can assign custom labels to your reference indeed, simply add the [label] option in \bibitem, e.g.

   \bibitem[Krummenacher, 1991]{Krummenacher1991} 
   F. Krummenacher, 
   \emph{Pixel detectors with local intelligence}, 
   NIM A305, 1991, 527-532

As an alternative you can use a BibTex database. See http://www.bibtex.org/.

Harvard referencing

Use the natbib package. Add

\usepackage[option(s)]{natbib}

in your preamble.

To create references you can use different versions of the basic \cite{} command to display the type of citation you want.

Common options:

  • round round parenthesis ()
  • square square parentheses []



Last update: Luca pacher - Oct 27, 2013