Topic 2 of 9 · Labs II–III
Technical Report Writing with LaTeX
Typesetting reports in LaTeX with Overleaf: text and special characters, errors, mathematics, lists, packages, sections, cross-references, figures, tables, algorithms and BibTeX citations.
← → move between slides · F full screen · M slide list
Before we start
Why this matters
Your final report will have 30 figures, 15 tables and 40 references. In a word processor, adding one figure in chapter 2 means renumbering everything after it by hand.
LaTeX numbers figures, tables, sections, equations and citations for you and keeps every cross-reference correct. It is also what IEEE, ACM and most universities expect for technical writing.
This topic covers Lab II (text, errors, maths, packages) and Lab III (structure, references, figures, tables, citations). The playground on the slides compiles as you type.
Outline · Labs II–III
Topics in this chapter
Select a topic to jump to the slide that explains it.
Concept 1 of 23
What LaTeX is
LaTeX (pronounced “lay-tek” or “lah-tek”) is a document preparation system used worldwide for scientific papers, theses, books and slides. You write plain text with commands; a compiler turns it into a beautifully typeset PDF.
- It separates content from style: change the document class or a package and the whole layout changes.
- It numbers sections, figures, tables and equations automatically and keeps every cross-reference right.
- It builds the table of contents and bibliography for you.
- Journals and conferences (IEEE, ACM, Springer) publish LaTeX templates: you add only the content.
Concept 1 of 23
What LaTeX is (cont.)
Getting started
Your first document
\documentclass{article}
\begin{document}
Hello World! % your content goes here...
\end{document}The comment after % is not printed.
- Commands start with a backslash
\. - Every document starts with
\documentclass; the argument in{ }says what kind:article,report,book,beamer(slides). - Optional arguments go in
[ ]:\documentclass[12pt,twocolumn]{article}. - A
%starts a comment: LaTeX ignores the rest of the line.
Everything before \begin{document} is the preamble (settings and packages). Everything between \begin{document} and \end{document} is the body that gets printed.
| Class | Use it for |
|---|---|
| article | lab reports, papers, short reports |
| report | long reports and theses with chapters |
| book | books |
| beamer | presentation slides |
Interactive
Try it: typesetting text
Interactive
Try it: typesetting text (cont.)
Words are separated by one or more spaces; paragraphs by one or more blank lines. Extra spaces in the source are collapsed in the output.
Typesetting text
Special characters
Ten characters have special meanings. Typing them directly causes an error or a surprise.
| Character | Meaning in LaTeX | To print it |
|---|---|---|
% | comment | \% |
$ | start/end maths | \$ |
& | table column separator | \& |
# | macro parameter | \# |
_ ^ | subscript / superscript (maths) | \_ \^{} |
{ } | grouping | \{ \} |
~ | non-breaking space | \textasciitilde |
\ | starts a command | \textbackslash |
Quotes: use `` and '' for “double” and ` ' for ‘single’ quotes.
Typesetting text
Special characters (cont.)
Typesetting text
Handling errors
When LaTeX cannot understand the source it stops with an error and a line number. For example, misspelling \emph as \meph gives Undefined control sequence.
Advice on errors
- Don’t panic — errors happen to everyone.
- Fix them as soon as they appear: if what you just typed caused an error, start there.
- If there are several errors, fix the first one; the cause may even be on a line above it.
| Message | Usual cause |
|---|---|
| Undefined control sequence | misspelt command, or a package not loaded |
| Missing $ inserted | _, ^ or a maths command used outside $…$; or a blank line inside maths |
| Misplaced alignment tab character & | an & in normal text: write \& |
| \begin{x} ended by \end{y} | environments closed in the wrong order |
| Environment align undefined | \usepackage{amsmath} missing |
| Reference … undefined | a \label is missing or misspelt; or compile again |
Exercise
Exercise 1: find and fix the errors
Exercise
Exercise 1: find and fix the errors (cont.)
Show the fixed text
The whole corrected source: select all of it and paste it over the text in the box above.
\documentclass{article}
\begin{document}
In March 2006, Congress raised that ceiling an additional \$0.79
trillion to \$8.97 trillion, which is approximately 68\% of GDP. As of
October 4, 2008, the ``Emergency Economic Stabilization Act of
2008'' raised the current debt ceiling to \$11.3 trillion.
\end{document}\$ and \% print the characters; ``…'' gives curly quotes instead of straight ".
Concept 7 of 23
Mathematics: inline and displayed
- Dollar signs mark maths in the text:
$c = a - b + 1$. Always use them in pairs. - LaTeX handles spacing in maths itself — it ignores your spaces.
- Big formulas go on their own line in an
equationenvironment, which is numbered;equation*(from amsmath) is unnumbered. - Do not leave blank lines inside maths.
| You type | You get |
|---|---|
x^2, x_i | superscript, subscript |
\frac{a}{b} | a fraction |
\sqrt{b^2-4ac} | a square root |
\sum_{k=1}^{n} | a sum with limits |
\alpha, \pi, \infty | Greek letters, ∞ |
\leq, \geq, \neq, \pm | ≤ ≥ ≠ ± |
Concept 7 of 23
Mathematics: inline and displayed (cont.)
The roots of a quadratic equation are given by
\begin{equation}
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
\end{equation}
where $a$, $b$ and $c$ are \ldots\sum is small with side limits in text, and large with limits above and below in a displayed equation.Mathematics
amsmath: operators and aligned equations
\usepackage{amsmath} % in the preamble
\begin{equation*}
\min_{x,y} (1-x)^2 + 100(y-x^2)^2
\end{equation*}
\begin{equation*}
\beta_i = \frac{\operatorname{Cov}(R_i, R_m)}{\operatorname{Var}(R_m)}
\end{equation*}
\begin{align*}
(x+1)^3 &= (x+1)(x+1)(x+1) \\
&= (x+1)(x^2 + 2x + 1) \\
&= x^3 + 3x^2 + 3x + 1
\end{align*}The three lines line up at the = signs, where the & is.
Mathematics
amsmath: operators and aligned equations (cont.)
- LaTeX reads adjacent letters as variables multiplied together, so
minwould print in italics. amsmath defines upright operators such as\min,\max,\log. \operatorname{Cov}makes your own operator.- In
align*,&marks the alignment point (before the =) and\\starts a new line. alignwithout the star numbers every line; add\nonumberto skip one.
Interactive
Try it: maths
Interactive
Try it: maths (cont.)
Change a formula and watch the page. Try deleting a $ or the \usepackage{amsmath} line to see the errors LaTeX gives.
Exercise
Exercise 2: typeset the central limit theorem
Exercise
Exercise 2: typeset the central limit theorem (cont.)
Show the answer
The whole corrected source: select all of it and paste it over the text in the box above.
\documentclass{article}
\usepackage{amsmath}
\begin{document}
Let $X_1, X_2, \ldots, X_n$ be a sequence of independent and identically
distributed random variables with $\operatorname{E}[X_i] = \mu$ and
$\operatorname{Var}[X_i] = \sigma^2 < \infty$, and let
\begin{equation*}
S_n = \frac{1}{n}\sum_{i=1}^{n} X_i
\end{equation*}
denote their mean. Then as $n$ approaches infinity, the random variables
$\sqrt{n}(S_n - \mu)$ converge in distribution to a normal $N(0, \sigma^2)$.
\end{document}Structure
Environments and lists
\begin{itemize} % bullet points
\item Biscuits
\item Tea
\end{itemize}
\begin{enumerate} % numbers
\item Biscuits
\item Tea
\begin{itemize}
\item green % lists can nest
\end{itemize}
\end{enumerate}
\begin{description}
\item[SRS] Software Requirements Specification
\end{description}Three lists: bullets, numbers with a nested bullet list inside item 2, and a description list with a bold label.
Structure
Environments and lists (cont.)
\begin{name}…\end{name}creates an environment: a context that changes how its content is typeset.itemizegives bullets,enumeratenumbers,descriptionbold labels.- Every
\beginneeds a matching\end, closed in reverse order. - You could even write
$…$as\begin{math}…\end{math}.
Concept 12 of 23
Packages
All the commands so far are built into LaTeX. Packages are libraries of extra commands; load each one with \usepackage in the preamble.
| Package | Gives you | Package | Gives you |
|---|---|---|---|
amsmath | equation*, align, \eqref, operators | graphicx | \includegraphics for images |
hyperref | clickable links and references | biblatex | citations and bibliography |
booktabs | professional table rules | caption, subcaption | caption styling, subfigures |
algorithm, algpseudocode | numbered pseudocode | listings | source code with highlighting |
geometry | page margins | xcolor | coloured text |
float | [H] “put the figure exactly here” | tabularx | tables that fill the line width |
Concept 12 of 23
Packages (cont.)
\documentclass{article}
\usepackage{amsmath} % preamble
\begin{document}
% now we can use commands from amsmath here...
\begin{align*}
a^2 + b^2 &= c^2 \\
\max(a, b) &\leq c
\end{align*}
\end{document}Delete line 2 and the previewer reports Environment align* undefined: align* comes from amsmath.
Concept 13 of 23
Title, abstract and sections
\documentclass{article}
\title{The Title}
\author{A. Author}
\date{\today}
\begin{document}
\maketitle
\begin{abstract}
Abstract goes here...
\end{abstract}
\tableofcontents
Concept 13 of 23
Title, abstract and sections (cont.)
\section{Introduction}
The problem of \ldots
\section{Method}
We investigate \ldots
\subsection{Sample Preparation}
\subsection{Data Collection}
\section{Results}
\section{Conclusion}
\end{document}Concept 13 of 23
Title, abstract and sections (cont.)
Concept 13 of 23
Title, abstract and sections (cont.)
Every heading is numbered for you, and the contents list is built from them (after the second compile).
- Tell LaTeX the
\title,\authorand\datein the preamble;\maketitleprints them. - The
abstractenvironment makes an abstract. \section,\subsection,\subsubsectionare numbered automatically (1, 1.1, 1.1.1).\section*gives an unnumbered heading that is left out of the table of contents.- In the
reportclass,\chaptersits above\section. \tableofcontentsneeds two compiles to fill in.
Structured documents
Labels and cross-references
\usepackage{amsmath} % for \eqref
...
\section{Introduction}
\label{sec:intro}
In Section~\ref{sec:method}, we \ldots
\section{Method}
\label{sec:method}
\begin{equation}
\label{eq:euler}
e^{i\pi} + 1 = 0
\end{equation}
By \eqref{eq:euler}, we have \ldots\ref{sec:method} became 2 and \eqref{eq:euler} became (1); the ~ keeps “Section” and “2” on one line.
Structured documents
Labels and cross-references (cont.)
- Put
\label{key}right after the thing you number (section, equation, caption). - Refer to it with
\ref{key};\eqref{key}adds brackets for equations. - Never type numbers yourself: if you add a section, every reference updates.
- Use prefixes so keys are readable:
sec:,fig:,tab:,eq:. - Write
Section~\ref{…}: the~stops the line breaking between the word and the number. - LaTeX needs two runs: the first records labels, the second prints them. Until then you see ??.
Interactive
Try it: a small report
Interactive
Try it: a small report (cont.)
Change the order of the sections and watch the numbers and the reference update. Delete a \label to see “??” and the warning.
Concept 16 of 23
Figures and floats
\usepackage{graphicx} % preamble
...
Figure~\ref{fig:model} shows \ldots
\begin{figure}[htbp]
\centering
\includegraphics[width=0.5\textwidth]{model}
\caption{The iterative model.}
\label{fig:model}
\end{figure}The striped box stands for your image file model.png. The caption is numbered and the reference says Figure 1.
Concept 16 of 23
Figures and floats (cont.)
\includegraphics(from graphicx) inserts JPEG, PNG or PDF images. Options:width=0.5\textwidth(half the text width),angle=270,scale=0.8.- Wrapping it in
figuremakes a float: LaTeX decides where it fits best. - Placement hints:
hhere,ttop,bbottom,pown page;[H](package float) forces “exactly here”. \labelmust come after\caption, or the reference points to the section instead.- Tables go in a
tablefloat, usually with the caption above.
Figures, tables and code
Subfigures
Load caption and subcaption, then place several subfigure environments inside one figure. \hfill spreads them across the line.
\begin{figure}
\centering
\begin{subfigure}[b]{0.3\textwidth}
\centering
\includegraphics[width=\textwidth]{graph1}
\caption{$y=x$}
\label{fig:y equals x}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.3\textwidth}
\centering
\includegraphics[width=\textwidth]{graph2}
\caption{$y=3\sin x$}
Figures, tables and code
Subfigures (cont.)
\label{fig:three sin x}
\end{subfigure}
\caption{Three simple graphs}
\label{fig:three graphs}
\end{figure}Each subfigure gets its own letter, (a) and (b), under one shared figure number.
Figures, tables and code
Tables
\begin{tabular}{|l|r|r|} \hline
Item & Qty & Unit \$ \\ \hline
Widget & 1 & 199.99 \\
Gadget & 2 & 399.99 \\
Cable & 3 & 19.99 \\ \hline
\end{tabular}- The argument gives the column alignment: left, centre, right;
p{3cm}wraps text. |draws vertical lines;\hlinedraws a horizontal line.&separates columns and\\ends a row — likealign*.- For reports, the booktabs style (
\toprule,\midrule,\bottomrule, no vertical lines) looks more professional.
Figures, tables and code
Tables (cont.)
Figures, tables and code
Algorithms and code listings
\usepackage{algorithm}
\usepackage{algpseudocode}
...
\begin{algorithm}
\caption{Withdraw cash}
\begin{algorithmic}[1] % [1] = number every line
\State $i \gets 10$
\If{$i \geq 5$}
\State $i \gets i - 1$
\Else
\If{$i \leq 3$}
\State $i \gets i + 2$
\EndIf
Figures, tables and code
Algorithms and code listings (cont.)
\EndIf
\end{algorithmic}
\end{algorithm}Figures, tables and code
Algorithms and code listings (cont.)
\If, \Else and \EndIf print the bold keywords and indent the lines for you.
Command names are title-cased: \State, \While, \EndWhile, \For, \Return. The algorithm float adds a caption and number. For real source code, use the listings package instead:
\usepackage{listings}
\begin{lstlisting}[language=Python]
def incmatrix(genl1, genl2):
m = len(genl1)
...
\end{lstlisting}The code is printed exactly as typed, in a typewriter font (Overleaf also colours the Python keywords).
Interactive
Try it: figures, tables and algorithms
Interactive
Try it: figures, tables and algorithms (cont.)
Swap the two subfigures, add a row to the table or a \State to the algorithm, and watch the numbers and layout follow.
Concept 21 of 23
Citations with BibTeX and biblatex
- Create a reference file with the .bib extension (Overleaf: New file →
citation.bib). - Find the paper, journal or book in Google Scholar.
- Click Cite → BibTeX to get the entry.
- Paste the entry into the .bib file.
- In the preamble:
\usepackage{biblatex}and\addbibresource{citation.bib}. - In the text:
\cite{key}; where the list should go:\printbibliography. - Compile (Overleaf runs biber and LaTeX again for you).
Concept 21 of 23
Citations with BibTeX and biblatex (cont.)
@article{guyot2002high,
title={High solid content latexes},
author={Guyot, A and Chu, F and Schneider, M and Graillat, C and McKenna, TF},
journal={Progress in Polymer Science},
volume={27}, number={8}, pages={1573--1615},
year={2002}, publisher={Elsevier}
}The entry appears like this in the list once it is cited with \cite{guyot2002high}.
Concept 21 of 23
Citations with BibTeX and biblatex (cont.)
Concept 21 of 23
Citations with BibTeX and biblatex (cont.)
\cite appear in the list. Use one style consistently (IEEE is common in computing: \usepackage[style=ieee]{biblatex}).Interactive
Build a BibTeX entry
Concept 23 of 23
Writing the technical report
| Section | Contents |
|---|---|
| Title page | course, project title, team members and IDs, date |
| Abstract | 150–250 words: problem, approach, result |
| Introduction | problem, motivation, objectives |
| Background / related work | existing systems with citations |
| Methodology & design | SRS, SDLC choice, DFD, UML, UI |
| Implementation / output | screens, results, figures with captions |
| Discussion & conclusion | what worked, limits, future work |
| References | generated from the .bib file |
- Every figure and table has a numbered caption and is referred to in the text before it appears.
- Write in plain, precise sentences; prefer active voice (“The system stores…”).
- Keep one file per chapter and join them with
\input{intro}— easier for a team. - Keep images in a
figures/folder; export diagrams as PDF or PNG at good resolution. - Academic integrity: cite every source; copied text or diagrams can cost full marks.
Worked example 1 of 3
Worked example 1
tab:cost.Show the solution
The profit was 25\% higher \& the cost fell by \$2,000
(see Table~\ref{tab:cost}).Assuming the table labelled tab:cost is the third table in the report.
%, & and $; never type the table number yourself.Worked example 2 of 3
Worked example 2
Show the solution
\begin{equation}
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
\label{eq:quadratic}
\end{equation}
Equation~\eqref{eq:quadratic} gives both roots.\eqref needs \usepackage{amsmath}.Worked example 3 of 3
Worked example 3
Show the solution
\label was placed before \caption (or outside the figure), so it captured the current section number (1.1). Move \label{fig:…} directly after \caption{…}.Practice
Practice (1 of 2)
Try each one on paper first, then check your answer.
\section{Results} and \section*{Results}?Show the answer
Show the answer
graphicx: add \usepackage{graphicx} to the preamble.Show the answer
\begin{tabular}{lcr}
\hline
Name & Qty & Price \\
\hline
Pen & 2 & 20 \\
\end{tabular}Practice
Practice (2 of 2)
Try each one on paper first, then check your answer.
Show the answer
\ref points to a label LaTeX does not know yet. Either the label is missing or misspelt, or the document needs to be compiled a second time.@inproceedings{rahman2023atm,.Show the answer
\cite{rahman2023atm} — the key is the text between { and the first comma.Show the answer
\begin{equation*}
S_n = \frac{1}{n}\sum_{i=1}^{n} X_i
\end{equation*}\[ … \] without any package.Check yourself
Quiz
Resources
Further learning
Hand-picked material to go deeper. Links open in a new tab.
Resources
Further learning (cont.)
Summary
Summary
- LaTeX separates content from style and numbers everything automatically; Overleaf compiles it online.
- Escape the special characters # $ % & _ { } ~ ^ \; fix the first error first.
- Maths goes in $…$ inline or equation/equation*/align* on its own line (amsmath).
- Load extra features with \usepackage in the preamble.
- Structure with \section; refer with \label + \ref/\eqref — never type numbers.
- Figures and tables are floats with \caption then \label; tables use & and \\.
- Cite with BibTeX: .bib file, \addbibresource, \cite, \printbibliography.