Skip to content

TeX and LaTeX#

TeX is a document typesetting system which was designed by Donald Knuth and later improved to LaTeX by Leslie Lamport. It allows the writer to define the general structure of a document (such as layout and sections), to stylise text (such as bold and italics), and to add citations and cross-references.

There exist several variants that are all based on the original TeX:

  • LaTeX: adds commands for easier typesetting of typical documents such as books, articles, and letters.
  • XeLaTeX: adds extended support for fonts and allows the use of system fonts.
  • LuaLaTeX: adds support for the scripting language Lua.

The Basics#

LaTeX code is divided into two parts: preamble and document. In the preamble you can add packages and specify the page layout. The document part starts with \begin{document} and ends with \end{document}. It defines the visible part of your document where you put your content. Everything after \end{document} will be ignored.

Example of a minimal .tex file
% Preamble
\title{My first article}

% Document

  This is the first paragraph.

Special Characters#

Some characters are not part of normal text but have a reserved special meaning for the LaTeX compiler.

  • \ introduces a command
  • {, } embraces arguments, creates logical parts
  • [, ] embraces optional command parameters
  • % comments: code after % will be ignored.
  • $ starts the inline math mode.
  • _, ^ indizes and exponents in mathmode. e.g. a
  • & separates columns in tables
  • # parameter for own command declarations

If you want to use thes characters in your text you need to put a backslash in front of them. E.g. type \% in the .tex file to produce % in the PDF. An exception is the backslash itself, which is typed as \textbackslash.

Basic Document Formatting#


LaTeX supports several levels for headings:

  1. \part{title} (only for books)
  2. \chapter{title} (only for books or reports)
  3. \section{title}
  4. \subsection{title}
  5. \subsubsection{title}
  6. \paragraph{title}
  7. \subparagraph{title}

Font Styles#

Text Style Argument Syntax Switch Syntax
italic \textit{italic} \itshape italic
bold \textbf{italic} \bfseries italic
Link \href{Link}{}


Environments span several lines and are enclosed within \begin{ENV} ... \end{ENV}, where ENV is the name of the environment.


There are three kinds of lists: 1. bullet points, 2. enumeration, and 3. descriptions.

\paragraph{Bullet Points (itemize)}
    \item first item
    \item second item with further points:
        \item first subitem
        \item second subitem


To include tables properly in your document, you should add to your preamble:

\RequirePackage{booktabs}     % better spacing and horizontal lines
\RequirePackage{multirow}     % for columns spanning multiple rows
  \begin{tabular}{ll} \toprule   % add more l's for more columns (or r/c)
    \thead{Title Column 1} & \thead{Title Column 2} \\ \midrule
    Cell 1                 & Cell 2                 \\
    Cell 3                 & Cell 4                 \\
  \caption{This is the full caption of the table. It should explain which numbers are shown.}
  \renewcommand{\arraystretch}{1.5}   % change vertical row spacing
  \renewcommand{\tabcolsep}{0.8em}    % change horizontal column spacing
    \multirow{2}{*}{\thead{Slices}}&              % column heading
    \multicolumn{2}{c}{\thead{error (\%)}} &&     % column heading
    \multicolumn{2}{c}{\thead{error (slices)}} \\ % column heading
               \cmidrule{2-3} \cmidrule{5-6}
              &  avg. &   max. &&  avg. &  max. \\ \midrule
    \hfill $< 50$    & $7.4$ & $73.5$ && $78$  & $625$ \\
    $50 ... 100$ & $3.1$ & $27.2$ && $116$ & $725$ \\
    \hfill $> 100$   & $1.8$ &  $9.0$ && $178$ & $825$ \\ \bottomrule
\caption{Professional looking table with random data.}

Some Notes on Tables#

  • Ommit vertical lines! This is how professional books and journals typeset tables.
  • To add extra vertical spacing: \renewcommand\arraystretch{1.5}
  • To change horizontal spacing: \renewcommand{\tabcolsep}{3pt}


To include figures properly in your document, you should add to your preamble:

\RequirePackage{graphicx}        % required to load images
\graphicspath{ {img/} {gfx/} }   % set default image subfolders

Afterwards, you can create figures using

  \includegraphics[width=\textwidth]{example-image-golden}  % replace "example-image-golden" with filename
  \caption{This is the full caption of the figure. It should explain what is shown and should be longer than one line.}
  \label{fig:example} % used for referencing.