Skip to content

Typesetting in LaTeX

Want access to the live Overleaf document?

Use this link to view the document used during the workshop:
https://www.overleaf.com/read/khrjdkrdzkfv#f685d7

Your first LaTeX document

The first step is to create a new LaTeX project. If working on your own machine you should create a new .tex file; alternatively, you can start a new project in Overleaf.

Try to paste the following simple example in your editor:

\documentclass{article}
\begin{document}
Hello World!
I'm now writing in \LaTeX and can't forget to compile my document.
\end{document}

After you paste your code don't forget to compile it to see the final result.

Let's understand the code:

  1. \documentclass{article}: The first line declares the document type, or its class. While in this example we're using the article class, one of the more common for documents such as papers, others include book or report.
  2. The main body of the document go between the \begin{document} and \end{document} tags. While you'll always have these in your LaTeX documents, they don't necessarily go right after the document type declaration.

Into the preamble

This section, before the \begin{document} tag its called the preamble. The preamble acts as the document’s setup section, where you define specifics such as languages to be used in the document; you load the packages you want to use, define metadata such as authors, among many other configurations.

Let's edit our initial document to add some configuration options to the preamble:

\documentclass[12pt, a4paper]{article}

\usepackage{graphicx}

\title{I'm Learning \LaTeX!}
\author{CESE Inc.}
\date{October 2025}

\begin{document}
Hello World!
I'm now writing in \LaTeX and can't forget to compile my document.
\end{document}

Let's understand the code:

  1. We've added two parameters to the class declaration that:
    • set the font size to 12pt
    • set the paper size to A4
  2. We've loading an external package, in this case graphicx to extend the LaTeX’s capabilities (we'll learn all about figures later on).
    graphicx is a package that you'll use very often as it enables the ability to import external graphics files (of many formats).
  3. We've set the title, author and date information, but you'll notice that it's nowhere to be found in the document body. That's because although you've defined the metadata you haven't placed it in the document body. Let's do that next!

Title, author and date information

As you know by now adding a title, author and date to your document requires both the definition in the preamble and the placement of the information in the body of the document.

To set the metadata you can use the following commands:

  • \title{}: to set the document's title
  • \author{}: to set the document's author(s)
    • \thanks: a thanks command can be added after the name of the author, inside the braces of the author command itself. It will add a superscript and a footnote with the text inside the braces.
  • \date{}: to typeset an arbitrary date, or use in conjunction with the \today command to always update the date when you compile the document

To typeset all these fields in the actual document body you can use the \maketitle command within the body of the document. Try the next example using all these commands.

\documentclass[12pt, a4paper]{article}

\usepackage{graphicx}

\title{I'm Learning \LaTeX!}
\author{CESE Inc.\thanks{Made possible by the CSI Team!}}
\date\today

\begin{document}
\maketitle
Hello World!
I'm now writing in \LaTeX and can't forget to compile my document.
\end{document}

Tip

Try now changing the document class to book and see the differences in the document

Bold, italics and underlining

Emphasizing text is another basic of all typesetting systems. In LaTeX the basics are covered by three simple commands:

  • Bold using the \textbf{...} command.
  • Italics using the \textit{...} command.
  • Underline using the \underline{...} command.

Of course you can mix and match all the above commands For example:

\begin{document}
At \textbf{CESE}, we use the \textit{knowledge generated in research to provide \textbf{high value-added niche services} to industrial enterprises} in areas such as \textbf{Manufacturing Systems Design}, \textbf{Manufacturing Systems Planning and Management}, \textit{Collaborative Platforms}, \underline{\textit{Supply Chain Strategy}}, \underline{\textbf{Manufacturing Intelligence}} or Construction Information Management.
\end{document}

Tip

In Overleaf and many other LaTeX editors you can use the shortcuts you may be familiar with to facilitate the use of these commands.
For example CTRL+b or Command ⌘-b will automatically insert the \textit{} command.
If you have text selected, it will even wrap the command around it!

There is also the \emph{...} command with is context aware.
If used in normal text it will produce italicised text, similar to the \textit{...} command. For example:

\begin{document}
Valid \emph{criticism} does you a favor.
\end{document}

But, if used in a section that is italicised to begin with, the italics will be removed to create the emphasis. See here:

\begin{document}
\textit{Valid \emph{criticism} does you a favor.}
\end{document}

If the text is bold, you'll also get italic with the \textit command:

\begin{document}
\textbf{Valid \emph{criticism} does you a favor.}
\end{document}

Basic document structure

Now that you know the basics for starting a document you also need to understand how to structure your writing. LaTeX is very flexible in how you divide you text, giving you the ability to use chapters, sections and/or paragraphs.

Paragraphs and line breaks

LaTeX is particular in distinguishing between new lines and paragraphs. By default it will ignore a single line break (one press of the enter key) so that

\begin{document}
This is
a single line of text
\end{document}

results in the same output as

\begin{document}
This is a single line of text
\end{document}

You can press the "enter" key twice, ending the current line and inserting a blank line to generate a new paragraph in the typeset document, alternatively you can use the \par command. This means you can start a new paragraph like this:

\begin{document}
This is a 
single line of text. Meanwhile... 

I'm a new paragraph. See the difference?
\end{document}

To start a new line (that is not a new paragraph) you can insert a manual line break using the \newline command.

\begin{document}
This is our first paragraph. We should now press the \verb|enter| 
key twice to start the second one.

This line will start a second paragraph.

I will start the third paragraph and then add \newline a manual line break which causes this text to start on a new line but remains part of the same paragraph. 

Alternatively, I can use the \par command to start a new line, which is also part of the same paragraph.
\end{document}

As you can see LaTeX automatically indents paragraphs (except immediately after document headings).

Danger

Although tempting, don't use the \par or \newline commands if you need paragraphs with larger spacing between them. Not just bad practice, it can interfere with typesetting algorithms and, in part, removes some of the reproducibility that makes LaTeX so useful.
Look into the \smallskip, \medskip, \bigskip, \smallbreak, \medbreak, \bigbreak commands!

Chapters and sections

Long documents eventually will need to be partitioned. Whether it be chapters, sections or subsections, LaTeX provides document-structuring commands, with their typeset output being dependant on the document class being used. We'll use the article class for our examples (as these are most likely the ones you'll come across more often).

Here's an examples of some text partitioned in sections and subsections:

\documentclass{article}
\begin{document}

\section{Introduction}

This is the first section.

Lorem  ipsum  dolor  sit  amet,  consectetuer  adipiscing  
elit. Etiam  lobortisfacilisis sem.  Nullam nec mi et 
neque pharetra sollicitudin.  Praesent imperdietmi nec ante. 
Donec ullamcorper, felis non sodales...

\section{Second Section}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit.  
Etiam lobortis facilisissem.  Nullam nec mi et neque pharetra 
sollicitudin.  Praesent imperdiet mi necante...

\subsection{First Subsection}
Praesent imperdietmi nec ante. Donec ullamcorper, felis non sodales...

\section*{Unnumbered Section}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.  
Etiam lobortis facilisissem...
\end{document}

Info

As you can see from this example, LaTeX takes care of numberings* so you don't have to.
Your first \section{} will automatically be section 1, your second \subsection{} will be 1.2 (the same will be applied to figures, tables, etc. More on this later on).
This becomes very useful if you need to move sections around or even alter the structure of your document.

Danger

This automatic numbering also comes with a warning: consistency is important! If you ever find yourself typing something like see section 3 for more details LaTeX will not be able to seamlessly update the section numbering.
When you need to reference a section (or figure, table, etc) in your document you must use the process described in the next section.

Let's understand the code:

  1. \section{Introduction} & \section{Second Section} define new, first level and numbered sections. This is one of the commands that you'll use most often.
  2. \subsection{First Subsection} defines a new numbered section that's nested inside of the previously defined section.

Labels, captions & referencing

Labels are very important in LaTeX as their how you can programmatically reference other sections, figures, tables or any other resource. While this is simple system to use, it's important to keep it in mind while writing and referencing to avoid having to later edit your document for referencing not done correctly.

You need two commands:

  • \label{...} to create the labels that you'll later user
  • \ref{...} to reference a label that has been defined (both previously or later in the document).

Inside of the curly brackets of the \label command you can chose how to later reference the content your labeling. While this is arbitrary and you can adjust it to what makes sense to you or the specific context your are using it in, a somewhat structured system is helpful to keep track of all the labels.
I, for example, like to pre-append my labels with the type of content I'm labeling. A section will be sec:NameOfSection, a figure fig:NameOfFigure, and a table tab:NameOfTable.

Danger

Avoid using numberings in labels, as these might get dynamically altered by LaTeX if you change your document structure.
While a \label{fig:Figure1} that later becomes dynamically captioned asFigure 2 will still be typeset correctly, it creates unnecessary confusion for you when editing the document.

Let's look at some examples.

\documentclass{article}
\begin{document}

\section{Introduction}
\label{sec:intro}

CESE is part of INESC TEC's Industrial and Systems Engineering cluster. The activities of the cluster result in high impact systems for decision-support, operations automation, management and intelligence, as well as in the provision of technology transfer and innovative consultancy services for applications in Industry, Retail, Healthcare, Energy, Mobility and Transports, and Agriculture.

You can get an overview of CESE's activities in section \ref{sec:glance}, learn more about CESE's Mission in section \ref{sec:mission} and discover our future in section \ref{sec:future}.

\section{CESE at a Glance}
\label{sec:glance}

As introduced in \ref{sec:intro}, at CESE, we use the knowledge generated in research to provide high value-added niche services to industrial enterprises in areas such as Manufacturing Systems Design, Manufacturing Systems Planning and Management, Collaborative Platforms, Supply Chain Strategy, Manufacturing Intelligence or Construction Information Management.

\subsection{Mission}
\label{sec:mission}

Our mission is to advance the scientific knowledge in enterprise systems engineering, fostering high impact management and ICT systems, and generating innovative services for industrial organisations.

\section{Our Future}
\label{sec:future}

We want to be recognised as a leading research centre in enterprise systems engineering and as a first choice in helping industrial organisations to achieve sustainable, high-performance levels.

\end{document}

Tip

If a resource that you reference in your document for any reason is missing (a figure that you've removed, for example) LaTeX will throw a warning, letting you know that something needs to be looked at.

Advanced

The \ref command will only give the number of the section you are referencing.
If you need the title of the section itself you can use the nameref package.

\documentclass{article}
\usepackage{nameref}

\begin{document}

\section{CESE at a Glance} 
\label{sec:glance}

At CESE, we use the (...)

\section{Summary}

As referenced in \nameref{intsec:glancero}.

\end{document}

Lists

Lists are another important document structure that you'll use often. In LaTeX lists are created using environments, that encapsulate the LaTeX code required to implement a specific typesetting feature

An environment starts with \begin{environment-name} and ends with \end{environment-name} where environment-name might be one of the list types: itemize for unordered lists, enumerate for ordered lists or description for definition lists.

\documentclass{article}
\begin{document}

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

\begin{enumerate}
  \item Item 3
  \item Item 4
\end{enumerate}

\begin{description}
  \item [Item 5] Definition of item 5
  \item [Item 5] Definition of item 6
\end{description}

\end{document}

All these environments can be nested to create lists within lists or sub-items:

\documentclass{article}
\begin{document}

\begin{enumerate}
  \item Item 1
  \begin{enumerate}
    \item Sub item 1
    \item Sub item 2
  \end{enumerate}

  \item Item 2
  \begin{description}
    \item[Sub item 3] Definition of sub item 3 
    \item[Sub item 4] Definition of sub item 4 
  \end{description}

  \item Item 3
\end{enumerate}

\end{document}

Info

Notice how the nested ordered list markings will be automatically changed to letters to avoid confusion.
If this is not the behaviour that you desire it can be customized in custom environments.

Math(ematics)

For many people, even some at CESE, LaTeX is the best way of typesetting mathematical expressions.
From the more simple notation to complex equations, LaTeX gives authors the flexibility and predictability that you can't get on other editors. It's no coincidence that LaTeX is mostly used in technical fields (and not just to how similar to a programming language it is...).

As with most things in (life) LaTeX, there are many ways of typesetting math in your documents.
Some of the more common are:

  • \(...\)
  • $...$
  • \begin{math}...\end{math}

These inline methods work well for quick expressions:

\documentclass{article}
\begin{document}

\begin{quote}
In physics, the mass-energy equivalence is stated 
by the equation \(E=mc^2\), discovered in 1905 by Albert Einstein.
\end{quote}

\begin{quote}
In physics, the mass-energy equivalence is stated 
by the equation \begin{math}E=mc^2\end{math}, discovered in 1905 by Albert Einstein.
\end{quote}

\end{document}

Let's understand the code:

Some more symbols that might be usefull:

\sum: Σ
\lambda: Λ
\epsilon ε
\pi: π
\rho: ρ
\delta: δ
\leq: <
\geq: >
\approx: ≈
\euro: €
\%: %
\quad: [space]
b_{CESE}: SuperscriptCESE
L^{CESE}: UnderscriptCESE

Figures

To add figures to your LaTeX document you can use the \includegraphics command and, additionally, the figure environment. This command is, however, not part of the built-in LaTeX features, needed to be imported by the graphicx package that you've seen appear before.

Info

The examples in this section use the figure bellow. Direct link here.

CESE Cover Figure

  • If you'r using Overleaf: save it to your computer and upload it to your Overleaf work environment
  • If you'r using a local instalation: save it to your computer, in the same directory as the .tex file you'r editing.

Let's look at an example document that imports a familiar figure:

\documentclass{article}
\usepackage{graphicx}

\begin{document}

\begin{figure}[h]
    \centering
    \includegraphics[width=0.75\textwidth]{images/ceseCover.jpg}
    \caption{CESE Cover Image}
    \label{fig:ceseCoverImage}
\end{figure}

Figure \ref{fig:ceseCoverImage} is the cover image used in CESE's INESC TEC page. This example is on page \pageref{fig:ceseCoverImage}.

\end{document}

Let's understand the code:

  1. \usepackage{graphicx}, in the document preamble, imports the graphicx package and makes its functionality available throughout the document
  2. \begin{figure}[h] and \end{figure}:
    1. Set up the environment for our figure
    2. Tell LaTeX roughly where to place it
  3. The \centering command centers the figure on the page.
  4. \includegraphics[width=0.75\textwidth]{images/cese.jpg} plays two roles:
    1. Defines the relative width of the figure. In this example we're setting it to 75% of the page's width.
    2. Tells LaTeX what figure to include. In this case the one called ceseCover
  5. The \caption command defines the caption for the figure
  6. The \label command defines label for the table so you can later reference it

Note

textwidth can be replaced with scale for sizing figures.
This would resize the figure relative to its original size.
scale=0.5 would imply a figure with half its original size.

Tables

Danger

Saying that table typesetting can get complex is an understatement.
We'll go over the basics of creating tables in LaTeX that cover most needs but be aware that complex tables require more complex code.

Here's an example, relatively simple table, that includes a caption and a label:

\begin{table}[h]
\centering
\begin{tabular}{llll}
0 & Coll A  & Coll B  & Coll C  \\
Row 1 & A1 & B1 & C1 \\
Row 2 & A2 & B2 & C2 \\
Row 3 & A3 & B3 & C3
\end{tabular}
\caption{Example Table}
\label{tab:exampleTable}
\end{table}

Let's understand the code:

  1. \begin{table}[h] and \end{table} set up the table environment
  2. The \centering command centers the table on the page.
  3. \begin{tabular}{llll} and \end{tabular} serve 3 functions:
    1. Set up the tabular environment, the actual content of the table
    2. Define the number of columns, the 4 l's in this example
    3. Define how the text in these columns is aligned, l for left, in this example
  4. Inside the tabular environment:
    1. The & character separates cells in a column
    2. The \\ characters break between table rows
  5. The \caption command defines the table caption
  6. The \label command defines label for the table so you can later reference it

Let's now make some changes to our table code:

\begin{table}[h]
\centering
\begin{tabular}{l|ccc}
0 & Coll A  & Coll B  & Coll C  \\ \hline
Row 1 & A1 & B1 & C1 \\
Row 2 & A2 & B2 & C2 \\
Row 3 & A3 & B3 & C3
\end{tabular}
\caption{Example Table}
\label{tab:exampleTable}
\end{table}

Let's understand the code:

  1. Now, when opening the tabular environment we:
    1. Define a vertical border line between the 1st and 2nd columns
    2. Center alight the text in the last three columns
  2. In the tabular we:
    1. Define a horizontal border line between the 1st and 2nd rows

Reference management

Question

For this section I'll assume you are already using a reference manager such as Mendeley or (preferably) Zotero.
If you are not... you should!

Bibliography management

LaTeX has a variety of features that make dealing with references much simpler, including built-in support for citing references. However, a much more powerful and flexible solution is achieved thanks to an auxiliary tool called BibTeX and, more recently, BibLaTeX.

A BibTeX database is stored as a plain text .bib file that can be viewed and edited easily. The structure of the file is also quite simple.

An example of a BibTeX entry:

@article{Silva2021,
  title = A Vision for a Platform-based Digital-Twin Ecosystem, 
  author = {Silva, Henrique Diogo and Azevedo, Miguel and Soares, Ant{\'o}nio Lucas},
  year = {2021},
  journal = {IFAC-PapersOnLine},
  volume = {54},
  number = {1},
  pages = {761--766},
  issn = {2405-8963},
  doi = {10.1016/j.ifacol.2021.08.088}
}

Each entry begins with the declaration of the reference type, in the form of @type. BibTeX knows of practically all types you can think of, common ones are: book, article, and for papers presented at conferences, there is inproceedings.

After the type (and the initial curly brace that signifies the beginning of the reference attributes) the first element that follows is the citation key, or the BibTeX key. This key must be unique for all entries in your bibliography. It is this identifier that you will use within your document to cross-reference it to this entry. It is up to you as to how you wish to label each reference, but there is a loose standard in which you use the author's surname, followed by the year of publication.

Bibliography styles are files recognized by BibTeX that tell it how to format the information stored in the .bib file when processed for output. And so the first command listed above is declaring which style file to use. The style file in this instance is plain.bst (which comes as standard with BibTeX). You do not need to add the .bst extension when using this command, as it is assumed. Despite its name, the plain style does a pretty good job (look at the output of this tutorial to see what I mean).

\bibliographystyle{plain}
\bibliography{paper_biblio}

Citations

To actually cite a given document is very easy. Go to the point where you want the citation to appear, and use the command \cite{cite_key}, where the cite_key is that of the item you wish to cite:

\cite{pasmore2019}

When LaTeX processes the document, the citation will be cross-referenced with the bibitems and replaced with the appropriate number citation. The advantage here, once again, is that LaTeX looks after the numbering for you. If it were totally manual, then adding or removing a reference would be a real chore, as you would have to re-number all the citations by hand.

When a sequence of multiple citations is needed, you should use a single \cite{} command, with multiple keys separated by commas:

\cite{pasmore1988,pasmore2019,badham2000}

Danger

Before changing the style of you citations and/or references check the documentation of your template/journal. Many of these settings are defined for you in the template and should not be altered.

Note

If you only want a reference to appear in the bibliography, but not where it is referenced in the main text, you can use the \nocite{} command:

This reference will not be shown here, only in the bibliography \nocite{silva2023}.


Last update: December 5, 2023