User Tools

Site Tools


software:latex:start

LaTeX

Latex is a document preparation system that can produce, through a typographical system called Tex, high-quality documents in PDF format.

Install LaTeX

Install the following packages via Synaptic:

  • texlive-base
  • texlive-bibtex-extra
  • texlive-lang-<lang>
  • texlive-latex-extra
  • texlive-science

where <lang> is the language name to use, like italian or other.

Frame of a LaTeX document

Hereafter will be made specific reference to the document class article which is the most popular in the academic circles.

The following is the main frame of a LaTeX document:

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\begin{document}
...
\end{document}

in which, the packages used, follow the syntax:

\usepackage[<options>]{<name-package>}

Further packages, must be declared before the \begin{document}.

Packages

FIXME remove this section and create as many sections as the packages listed

The following packages are the most important:

package description
inputenc support for different encoding characters; it's necessary to specify the <encoding> to use:
\usepackage[<encoding>]{inputenc}
babel culturally-determined typographical rules; it's necessary to specify the <language> at which it's applied:
\usepackage[<language>]{babel}
amsmath mathematical typesetting
amsfonts set of fonts to use in mathematics
amssymb symbols to use in mathematics
siunitx measure unit associated with formula
pdflscape allow to rotate pages in landscape format

Table of Contents

To create a table of contents use the code:

\documentclass{article}
\begin{document}
 
\tableofcontents
\pagebreak
 
\section{Introduction}
...
\end{document}

Numbered sections will be automatically displayed into the TOC, otherwise, they have to be manually added:

\section*{<section-name>}
\addcontentsline{toc}{section}{<section-name>}

The document must be built 2 times: first the document, then the TOC.

Centered Box

To create a box around an object and to equally centre both horizontally and vertically, use the code:

\documentclass{article}
\usepackage[showframe]{geometry}
\begin{document}
\vspace*{\fill}
\noindent
\hspace*{\fill}\framebox[.5\linewidth][c]{text}\hspace*{\fill} \\
\vspace*{\fill} \\
\hspace*{\fill}\framebox[.5\linewidth][c]{text}\hspace*{\fill} \\
\vspace*{\fill}
\end{document}
Figure 1: Box equally spaced. The margin around the page have been rendered visible using \usepackage[showframe]{geometry}.

Measure Unit

To type physical quantities use the package:

\usepackage{siunitx}

Then use the code:

\documentclass{article}
\usepackage{siunitx}
\begin{document}
$$
\SI{100}{kg} \times \SI{9.81}{m/s^2} \simeq \SI{1e3}{kN}
$$

\SI{1e3}{kN} \\
\num{1e3} \\
\si{kN} 
\end{document}

Minipage

The minipage environment is useful to insert objects side-by-side. It follows is an example:

\begin{document}

\noindent
\begin{minipage}{.5\linewidth}
\captionof{table}{<caption>}
\label{<tab:name-ref>}
\centering
\begin{tabular}{<column-alignment>}
\end{tabular} 
\end{minipage}%
\begin{minipage}{.5\linewidth}
\centering
\includegraphics{<path/img>} 
\captionof{figure}{<caption>}
\label{<fig:name-ref>}
\end{minipage}

\end{document}
  • Since a minipage creates a new paragraph, it is automatically indented; this could bring a warning of overfull box. The command \noindent prevents it.
  • Between the two minipages any space mustn't be present. The comment character % prevents it.
  • Since minipage isn't a float object, captions must be created with the command \captionof{<float-type>}{<caption>} which required the package \usepackage{caption}

If a margin is desired between the two minipages, the following code can be used:

\noindent
\begin{minipage}{.45\linewidth}
...
\end{minipage}\hfill
\begin{minipage}{.45\linewidth}
...
\end{minipage}

Rotate page

To rotate a page in landscape format without changing the orientation of the content, use the package:

\usepackage{pdflscape}

Then use the code:

\begin{landscape}
...
\end{landscape}

Rotate object

To rotate any kind of object, use the package graphicx, then the code:

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\rotatebox[origin=c]{180}{text}
\end{document}

in which the syntax is:

\rotatebox[origin=<lrctbB>]{<angle>}{<obj>}

In case the object is a figure, use the code:

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\includegraphics[angle=90,origin=c]{image.pdf}
\end{document}

Table with text rotate 90° in a rowspan cell

To span a cell over rows it's necessary the packages graphicx and multirow, then the code:

\documentclass{article}
\usepackage{graphicx}
\usepackage{multirow}
\begin{document}
\begin{tabular}{c|cc}
& c2 & c3 \\
\hline
\multirow{3}{*}{\rotatebox[origin=c]{90}{text}} & r1c2 & r1c3 \\
& r2c2 & r2c3 \\
& r3c2 & r3c3 \\
\end{tabular}
\end{document}

in which the syntax is:

\multirow{<rows-to-span>}{<width>}{<text>}
Figure 2: Table with a cell which spans two and more rows.

Footnote at the bottom of the page

Necessary the package:

\usepackage[bottom]{footmisc}

Bibliography

The bibliography is created using a BibTex database of the works consulted. This is the code to import it in the LaTeX document:

\usepackage[backend=bibtex, bibencoding=ascii, style=numeric]{biblatex}
 
\bibliography{bibliography}  % imports bibliography
 
\begin{document}
...
\pagebreak 
\printbibliography  % prints bibliography
\end{document}

where the bibliography.bib file has the following structure:

@book{1,
author = {...},
title = {...},
year = {...},
editor = {...},
pages = {..},
}
 
@book{2,
author = {...},
title = {...},
year = {...},
editor = {...},
pages = {..},
}
 
...
}

and the reference to each work is of the form:

\begin{document}
...
\cite{1} ... \cite{2}
...
\pagebreak 
\printbibliography  % prints bibliography
\end{document}

It's necessary to change how Texmaker builds the document.

software/latex/start.txt · Last modified: 2020/05/03 19:00 by tormec