This tutorial is on the typesetting language called LaTeX. LaTeX is useful when it comes to creating complex documents like thesis, project reports, research articles, etc. We will see the basic use-cases in around 22 examples.
LaTeX Installation Instructions
Windows
In Windows, you need to install two programs called MiKTeX and TeXstudio. Please be careful to install MiKTeX first and TeXstudio only after that. TeXstudio is the editor or IDE using which we will be creating documents, and MiKTeX is the core program running in the backend.
- Download and install the latest MiKTeX from: https://miktex.org/download. Follow https://miktex.org/howto/install-miktex if you need additional instructions with screenshots.
- Then download and install the latest TeXstudio from: https://www.texstudio.org/.
Ubuntu
You can follow the video https://www.youtube.com/watch?v=t7Z_fAV8A0E to install LaTeX core files and TeXstudio in Ubuntu. Please note that it might take a while to do the texlive installation (∼2GB) depending on your bandwidth.
Overleaf
Overleaf is a free online LaTeX editor with added features like real-time collaboration, version control, built-in templates, etc. If you are having problems with the above installation steps, you can still practice creating LaTeX documents using this service.
Some of the other advantages include no installation or library issues, can access the files from wherever you want (home or office), and files are stored in the free cloud storage (no need to worry about backup).
You need to register for a free account at https://www.overleaf.com/register by giving your email and setting a new password for overleaf. You might need to accept a confirmation mail received to the email ID you provided. Alternatively, you can use the service with your Google account as well.
Exercises
Once you are ready with the installation or setup you can start creating documents. Following is a set of basic LaTeX document creation exercises
Exercise 1 : Simple Document
The following is the LaTeX source code for the most simple document. Anything above the ‘\begin{document}’ is called a preample, where we load necessary libraries.
\documentclass{article}
\begin{document}
First document
\end{document}
Exercise 2 : Print Size
Now we will gradually see additional functionalities. We can set the font size and the margin sizes (the preset sizes can be A4 or letterpaper) as follows. The utf8 encoding line is recommended in all examples and is related to the character encoding to accommodate for any type of language/character set.
\documentclass[12pt, letterpaper]{article}
\usepackage[utf8]{inputenc}
\begin{document}
First document
\end{document}
Exercise 3 : Setting Margins
There is a package called geometry using which we can set custom margins on all four sides of the document.
\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[a4paper,width=145mm,top=30.5mm, bottom=30.5mm, bindingoffset=6mm]{geometry}
\begin{document}
Overleaf is a free online LaTeX editor with added features like real-time collaboration, version control, built-in templates, etc. If you are having problems with the above installation steps, you can still practice creating LaTeX documents using this service. Some of the other advantages include no installation or library issues, can access the files from wherever you want (home or office), and files are stored in the free cloud storage (no need to worry about backup).
\end{document}
Exercise 4A : Basic Formatting
We can set the font size using’\fontsize’ command. The parameters are the font size and 1.2 times of that font size.
\documentclass{article}
\usepackage[utf8]{inputenc}
\begin{document}
\fontsize{20}{24} \selectfont
Whatever text you insert here will appear in the selected font size.
\end{document}
You can select font types from a list of available fonts. Please see https://www.overleaf.com/learn/latex/Font_typefaces or https://tug.org/FontCatalogue/ for a list of fonts available.
\documentclass{article}
\usepackage[utf8]{inputenc}
\begin{document}
{\fontfamily{phv}\selectfont
This text uses a different font typeface
}
{\fontfamily{lmss}\selectfont
This text uses a different font typeface
}
\end{document}
Exercise 4B : Basic Formatting
A quick example of how to boldface parts of a text and intend or not intend a paragraph.
\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[a4paper,width=145mm,top=30.5mm, bottom=30.5mm, bindingoffset=6mm]{geometry}
\begin{document}
\noindent \LARGE {First sentence}\\
\textbf{Second sentence}
\end{document}
Exercise 4C : Basic Formatting
Some more basic formatting examples
\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[a4paper,width=145mm,top=30.5mm, bottom=30.5mm, bindingoffset=6mm]{geometry}
\begin{document}
Some of the \textbf{greatest} discoveries in \underline{science} were made by \textbf{\textit{accident}} \\
According to consensus in modern genetics, anatomically modern humans first arrived on the Indian subcontinent from Africa between 73,000 and 55,000 years ago. However, the earliest known human remains in India date to 30,000 years ago.
\vspace{2mm}
Settled life, which involves the transition from foraging to farming and pastoralism, began in Greater India around 7,000 BCE. At the site of Mehrgarh, presence can be documented of the domestication of wheat and barley, rapidly followed by that of goats, sheep, and cattle. By 4,500 BCE, settled life had spread more widely, and began to gradually evolve into the Indus Valley Civilization, an early civilization of the Old world, which was contemporaneous with Ancient Egypt and Mesopotamia. This civilization flourished between 2,500 BCE and 1900 BCE in what today is Pakistan and north-western India and was noted for its urban planning, baked brick houses, elaborate drainage, and water supply.
\end{document}
You can left alight, right align, or center text and other things using the following commands
\documentclass{article}
\usepackage[utf8]{inputenc}
\begin{document}
\begin{flushleft}
Left Text
\end{flushleft}
\begin{center}
Center Text
\end{center}
\begin{flushright}
Right Text
\end{flushright}
\end{document}
Exercise 4D : Page Numbering
You can select different page numbering styles shown below.
\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[a4paper,width=145mm,top=30.5mm, bottom=30.5mm, bindingoffset=6mm]{geometry}
%\pagenumbering{arabic}
%\pagenumbering{roman}
\pagenumbering{Roman}
%\pagenumbering{alph}
%\pagenumbering{Alph}
%\pagenumbering{gobble}
\begin{document}
Ut nec ligula. Turpis nullam. Fames. Mattis praesent velit vehicula. Viverra nostra cras euismod quis fames primis luctus ipsum euismod. Arcu lorem, nisl phasellus ultricies ridiculus litora sapien posuere. Donec erat cursus placerat facilisi praesent duis bibendum lobortis congue, semper aliquam molestie dui. Sit quam nascetur fusce mus condimentum mus fringilla fames felis arcu, curae; odio, habitasse conubia. Laoreet aptent nonummy et, iaculis mus auctor eleifend Hymenaeos, hendrerit rutrum etiam risus consequat etiam. Condimentum leo vehicula cras convallis pretium leo cubilia vestibulum venenatis Venenatis quam luctus. Placerat tempor fames tristique, nonummy Aliquet. Rutrum sodales quis aenean parturient amet quis natoque id habitasse mus vitae, suscipit. Inceptos, scelerisque sapien.
Habitasse class nibh. Consectetuer magna pretium integer ligula curabitur. Morbi malesuada curae; commodo volutpat elementum mollis semper tortor vivamus dictum tincidunt nisi sociis sociosqu auctor, iaculis lobortis curae; nec varius neque neque fames nulla vehicula eros condimentum consectetuer ridiculus. Fusce nec dapibus tincidunt interdum arcu. Nisl inceptos pharetra sodales elementum. Fermentum torquent donec lobortis. Penatibus tempus accumsan litora, feugiat. Tempus. Pede lectus volutpat, natoque eros semper consequat phasellus fusce. Duis pharetra vitae proin hymenaeos ultrices dis rutrum velit justo ultricies malesuada, torquent gravida torquent dis cras maecenas blandit purus sodales Mus sociis. Congue metus ullamcorper, arcu lorem, et. Urna cursus senectus Ornare dis faucibus vitae eros mollis. Nam nunc. Leo vel erat ligula egestas mattis hac orci nisi morbi a ante per. Odio. Rhoncus malesuada, aliquam elit arcu ipsum eget venenatis cursus.
Integer hymenaeos est nostra erat, sed massa euismod vitae eleifend dictum mus nisl eget Nisl vel libero sodales senectus commodo nibh donec ultricies eleifend per quis, cubilia enim per hac leo non dui in non augue consectetuer. Sollicitudin sed lobortis ridiculus dui sociosqu ligula urna aptent eget fringilla aptent elit rhoncus. Vivamus porttitor suscipit eu. Bibendum faucibus placerat penatibus sollicitudin praesent blandit leo tellus montes eleifend eget nostra per torquent ultrices cum sodales fringilla rutrum ut aliquet libero facilisis habitant nullam proin, torquent. Cubilia nisl sagittis pellentesque scelerisque consequat feugiat orci Quis. Ornare. Dolor dolor quisque metus dictum nunc ad per enim semper hac nam. Inceptos.
Fames sed dapibus lobortis, bibendum pede est tempus adipiscing pede commodo cum accumsan nullam aenean cubilia tellus dictum conubia ad vehicula aptent elit suscipit consectetuer Primis. Litora, mattis curae; parturient auctor tincidunt porta eleifend habitant Volutpat, massa, dignissim adipiscing turpis augue lacinia maecenas aenean consequat interdum porttitor cubilia dapibus magna mus. Nec metus diam malesuada rhoncus mattis elit penatibus. Hendrerit at sociis viverra feugiat gravida augue interdum mauris, egestas metus nibh inceptos. Aliquet. Ultrices penatibus lectus. Nascetur varius vehicula. Dictum augue tempor elit magnis fames. Congue vel fames interdum ad elit Nec.
Quisque libero tellus tempor enim, velit habitant inceptos cubilia venenatis duis litora nonummy ullamcorper magna fringilla tempor condimentum ornare malesuada mattis sodales. Eleifend etiam Turpis facilisis dapibus sociis velit elit integer morbi Ornare dui molestie massa eleifend urna. Platea congue hac odio id eros porttitor enim massa venenatis vehicula per rhoncus conubia pulvinar pulvinar rutrum vestibulum nibh morbi habitasse etiam nullam amet eleifend fermentum Pede felis tortor ad libero convallis pellentesque cras, orci platea consectetuer pede.
Lacinia pharetra odio cubilia ipsum gravida mollis. Massa luctus non rutrum donec senectus vulputate tortor viverra. Bibendum suscipit elit. Nulla ullamcorper sagittis, vitae. Venenatis turpis convallis sodales. Arcu enim cubilia rutrum faucibus tellus. Nec accumsan litora. Semper a blandit sociosqu nonummy ultrices volutpat interdum mauris elementum eget, euismod. Sodales mollis tristique. Eu vulputate sociosqu. Ullamcorper, magna nam. Vestibulum orci viverra sed eros venenatis litora leo eget torquent Velit dapibus.
Mus lacus imperdiet malesuada sit dis quis nam platea Dui eu pede sit cursus per tristique etiam nec elit, magna. Ut arcu sodales pretium fermentum tristique cum facilisis arcu platea volutpat curae; per. Eget fames viverra penatibus netus consequat curabitur in etiam congue. Vel id eleifend non, class blandit sodales in. Ullamcorper erat adipiscing taciti ante scelerisque nonummy pretium senectus cursus lacus litora dignissim ornare sagittis.
Rhoncus pharetra dolor sapien iaculis Consectetuer quis venenatis auctor arcu consequat porttitor nascetur libero felis lectus ullamcorper facilisi cursus, nullam praesent dictumst lacus luctus fringilla risus tempus placerat lorem velit suscipit quisque pulvinar diam congue purus aptent malesuada malesuada natoque. Amet lacinia sociis interdum magnis erat sapien vel congue et nonummy quis vel sagittis sagittis natoque eget etiam aliquet ac Tristique duis maecenas vitae quam sagittis class, dictumst nullam nullam vulputate. Metus ante. Pede tortor nostra id.
Mus inceptos orci mi in litora ullamcorper nostra elit nascetur sem. Dictumst. Montes class ultricies, sodales malesuada. Diam aptent consequat cursus Eros augue convallis arcu per elementum nibh vivamus. Quisque pharetra consectetuer iaculis pharetra sollicitudin ullamcorper. Purus cubilia pellentesque eu nunc bibendum Mattis nunc, torquent cursus suscipit in etiam elementum ipsum augue nullam nostra ornare lectus bibendum penatibus scelerisque fringilla cursus aenean. Erat ut penatibus euismod tellus adipiscing lobortis ornare volutpat arcu ligula ornare massa. Inceptos magna, libero nulla. Facilisis Arcu. Inceptos facilisi justo id curabitur placerat mattis elementum ultricies ultrices faucibus aliquet nisl ligula urna dictumst commodo cubilia mollis montes. Donec aliquet pretium quis viverra enim, cum aliquet. Imperdiet. Nunc dictum curabitur convallis, cum. Etiam. Quisque.
Cursus vulputate ut eleifend nibh eleifend. Dictumst metus feugiat adipiscing, magna primis nunc neque. Elementum egestas. Dictum rhoncus mauris ante. Egestas platea rhoncus aliquet a consequat montes malesuada magnis. Sapien enim adipiscing habitasse dictumst sed facilisi. Faucibus. Non pulvinar aenean eros habitasse auctor aliquam. Praesent potenti donec nullam nibh ultrices, phasellus, consequat sociosqu volutpat tempor ridiculus in cum tempus nonummy quam sociis Tincidunt nisi, orci, nisl non egestas erat rutrum praesent nam adipiscing felis. Etiam montes. Congue, class tortor convallis. Eleifend aenean mus fusce. Torquent tempor vitae hendrerit interdum. Per praesent convallis commodo potenti duis velit. Ligula penatibus aliquam ultricies ultrices feugiat dignissim ornare. Vestibulum torquent accumsan ad aliquet. Parturient nec, molestie. Tincidunt tincidunt ultrices duis purus facilisi facilisis sagittis cursus lorem ultricies eget aliquam tortor netus. Est commodo consequat quam a etiam aliquam integer nulla conubia vehicula cursus torquent elit felis in vel nunc massa. Donec class litora nonummy. Gravida scelerisque class enim donec dictumst risus.
\end{document}
Exercise 4E : Reset Page Numbering
\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[a4paper]{geometry}
\setcounter{page}{10}
\begin{document}
your content here
\end{document}
Exercise 5 : Watermark
We can use the package draft watermark library to create a watermark to documents with custom text and size.
\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[a4paper,width=145mm,top=30.5mm, bottom=30.5mm, bindingoffset=6mm]{geometry}
\usepackage{draftwatermark}
\SetWatermarkLightness{0.6}
\SetWatermarkScale{2}
\SetWatermarkText{Preview Only}
\begin{document}
Some of the \textbf{greatest} discoveries in \underline{science} were made by \textbf{\textit{accident}} \\
According to consensus in modern genetics, anatomically modern humans first arrived on the Indian subcontinent from Africa between 73,000 and 55,000 years ago. However, the earliest known human remains in India date to 30,000 years ago.
\vspace{2mm}
Settled life, which involves the transition from foraging to farming and pastoralism, began in Greater India around 7,000 BCE. At the site of Mehrgarh, presence can be documented of the domestication of wheat and barley, rapidly followed by that of goats, sheep, and cattle. By 4,500 BCE, settled life had spread more widely, and began to gradually evolve into the Indus Valley Civilization, an early civilization of the Old world, which was contemporaneous with Ancient Egypt and Mesopotamia. This civilization flourished between 2,500 BCE and 1900 BCE in what today is Pakistan and north-western India and was noted for its urban planning, baked brick houses, elaborate drainage, and water supply.
\end{document}
Exercise 6 : Columns & Line spacing
This example shows how to make a document double column, custom line spacing, and single side or double side.
\documentclass[11pt,oneside,twocolumn]{article}
\renewcommand{\baselinestretch}{1.5}
\usepackage[utf8]{inputenc}
\begin{document}
\section{Introduction}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam nunc ligula, tincidunt id diam quis, dictum tincidunt libero. Sed semper dolor ut neque vestibulum ornare. Aenean eget sapien efficitur, maximus odio a, ornare orci. Quisque nec luctus odio, et dictum massa. Nullam non libero eros. Aenean tincidunt ante et libero condimentum consectetur. Etiam ut ante non mauris egestas viverra sit amet ullamcorper justo. Pellentesque nibh velit, ornare non molestie quis, vehicula vitae lacus.
\section{Theory}
Fusce ac venenatis tellus. Aliquam ac eleifend tortor. Mauris sapien tortor, vulputate at lacinia nec, tincidunt et leo. Aliquam erat volutpat. Donec rutrum consectetur lacinia. Morbi eu nisl justo. Sed sagittis molestie justo, eu venenatis tellus lacinia sed.\\
\noindent Maecenas iaculis purus vitae enim dapibus, condimentum dapibus massa feugiat. Praesent cursus sem quis mattis ornare. Donec a vulputate orci. Fusce hendrerit, odio id finibus egestas, leo nunc fermentum sem, non pharetra ipsum felis ac elit. Phasellus ultrices bibendum leo, at posuere tellus feugiat id. Nunc vitae enim sed est malesuada fermentum quis sit amet ex. Etiam sit amet mauris vel augue tincidunt commodo non quis nisi. Quisque a nisi risus. Quisque id ultricies tellus, vel venenatis justo. Pellentesque non eros ut mauris feugiat eleifend. Suspendisse varius rutrum ante, eu euismod arcu mattis sed. Vestibulum egestas leo nisi, sed ultrices velit auctor vel.
\section{Conclusion}
Ut non mauris faucibus, aliquet turpis et, tincidunt enim. Curabitur auctor est id sapien gravida aliquam. Cras convallis elementum varius. Fusce nec luctus felis. Mauris a massa vel erat tristique volutpat. Donec tortor nunc, bibendum auctor accumsan quis, euismod vel mauris. Nunc justo odio, faucibus vel accumsan.
Ut non mauris faucibus, aliquet turpis et, tincidunt enim. Curabitur auctor est id sapien gravida aliquam. Cras convallis elementum varius. Fusce nec luctus felis. Mauris a massa vel erat tristique volutpat. Donec tortor nunc, bibendum auctor accumsan quis, euismod vel mauris. Nunc justo odio, faucibus vel accumsan.
\end{document}
Excercise 6A : Multi-column text
You can easily define the number of columns and space separation with them using the package called ‘multicol’
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{multicol}
\setlength{\columnsep}{5mm}
\begin{document}
\begin{multicols}{2}
Whatever you put here will be distributed across multiple columns you defined.
\end{multicols}
\end{document}
Excercise 6B : Multi-column text
You can exclude parts of text from columns and allow it to fill first column then next.
\documentclass{article}
\usepackage{multicol}
\begin{document}
\begin{multicols*}{2}
[This content is excluded from columns.]
Here the content is filled in column 1 first.
\end{multicols*}
\end{document}
Exercise 7 : Title and Abstract
This is how we can add a title and abstract to a simple LaTeX document.
\documentclass{article}
\usepackage[utf8]{inputenc}
\title{ExampleAbstract}
\author{sajilck }
\date{\today}
% \date{January 20, 2019}
\begin{document}
\maketitle
\begin{abstract}
Spencer, a neuroscientist focusing on sleep at the University of Massachusetts Amherst, wanted to investigate the science behind this anecdotal experience. “The observation of a lot of people is that a napless kid is emotionally dysregulated,” she says.
\end{abstract}
Research has already shown that, in general, sleep helps us make sense of emotions. Sleep plays a key role in encoding information based on experiences from the day, making sleep critical for preserving memories. And emotional memories are unique because of the way they activate the amygdala, the brain’s emotional core.
\end{document}
Exercise 8A : Simple Image Insert
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\includegraphics[width=0.5\textwidth]{universe.jpg}
\end{document}
Exercise 8B : Scaling, Resizing, Rotating Images
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\includegraphics{universe.jpg}
\newline
\includegraphics[width=2cm, height=3cm]{universe.jpg}
\newline
\includegraphics[scale=1.5]{universe.jpg}
\newline
\includegraphics[scale=0.5, angle=55]{universe.jpg}
\end{document}
Exercise 8C : Figures
The figures are easily inserted using the ‘graphicx’ package. After the ‘\begin{figure}’, we give all other settings like alignment, the path to the image, caption, and label.
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\section{Introduction}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam nunc ligula, tincidunt id diam quis, dictum tincidunt libero. Sed semper dolor ut neque vestibulum ornare. Aenean eget sapien efficitur, maximus odio a, ornare orci. Quisque nec luctus odio, et dictum massa. Nullam non libero eros. Aenean tincidunt ante et libero condimentum consectetur. Etiam ut ante non mauris egestas viverra sit amet ullamcorper justo. Pellentesque nibh velit, ornare non molestie quis, vehicula vitae lacus. The sunrise picture is shown in Figure \ref{fig:universe}.
\begin{figure}[h!]
\centering
\includegraphics[width=0.5\textwidth]{photo.jpeg}
\caption{The Universe}
\label{fig:universe}
\end{figure}
semper dolor ut neque vestibulum ornare. Aenean eget sapien efficitur, maximus odio a, ornare orci. Quisque nec luctus odio, et dictum massa. Nullam non libero eros. Aenean tincidunt ante et libero condimentum consectetur. Etiam ut ante non mauris egestas viverra sit amet ullamcorper justo. Pellentesque nibh velit, ornare non molestie quis, vehicula vitae lacus.\\
semper dolor ut neque vestibulum ornare. Aenean eget sapien efficitur, maximus odio a, ornare orci. Quisque nec luctus odio, et dictum massa. Nullam non libero eros. Aenean tincidunt ante et libero condimentum consectetur. Etiam ut ante non mauris egestas viverra sit amet ullamcorper justo. Pellentesque nibh velit, ornare non molestie quis, vehicula vitae lacus.\\
Nullam non libero eros. Aenean tincidunt ante et libero condimentum consectetur. Etiam ut ante non mauris egestas viverra sit amet ullamcorper justo. Pellentesque nibh velit, ornare non molestie quis, vehicula vitae lacus. Nullam non libero eros. Aenean tincidunt ante et libero condimentum consectetur. Etiam ut ante non mauris egestas viverra sit amet ullamcorper justo.
\end{document}
Exercise 8D : Figures-Setting Image Path
\documentclass{article}
\usepackage{graphicx}
\graphicspath{{./Images/}}
\begin{document}
\begin{figure}[h!]
\centering
\includegraphics[width=0.5\textwidth]{universe.jpg}
\caption{The Universe}
\label{fig:universe}
\end{figure}
\end{document}
Exercise 9 : Sub-figures
Similiar syntax exists for inserting sub-figures. The sub-figure commands are given inside the figure command.
\documentclass[12pt,twoside]{report}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\begin{document}
\begin{figure}
\centering
\begin{subfigure}[b]{0.25\textwidth}
\includegraphics[width=\linewidth]{photo.jpeg}
\caption{Universe 1}
\label{fig:a}
\end{subfigure}%
\begin{subfigure}[b]{0.25\textwidth}
\includegraphics[width=\linewidth]{photo.jpeg}
\caption{Universe 2}
\label{fig:b}
\end{subfigure}
\caption{Pictures of animals}\label{fig:animals}
\end{figure}
Figure \ref{fig:a} shows universe 1 and Figure \ref{fig:b} shows universe 2.
\end{document}
Exercise 9A : Sub-figures
You can choose to put images in grid style by adjusting its individual width.
\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\begin{document}
\section*{Introduction}
semper dolor ut neque vestibulum ornare. Aenean eget sapien efficitur, maximus odio a, ornare orci. Quisque nec luctus odio, et dictum massa. Nullam non libero eros. Aenean tincidunt ante et libero condimentum consectetur. Etiam ut ante non mauris egestas viverra sit amet ullamcorper justo. Pellentesque nibh velit, ornare non molestie quis, vehicula vitae lacus.\\
\begin{figure}[h!]
\centering
\begin{subfigure}[b]{0.33\textwidth}
\includegraphics[width=\linewidth]{universe.jpg}
\caption{Universe 1}
\label{fig:a}
\end{subfigure}
\begin{subfigure}[b]{0.33\textwidth}
\includegraphics[width=\linewidth]{universe.jpg}
\caption{Universe 2}
\label{fig:b}
\end{subfigure}
\begin{subfigure}[b]{0.33\textwidth}
\includegraphics[width=\linewidth]{universe.jpg}
\caption{Universe 3}
\label{fig:c}
\end{subfigure}
\begin{subfigure}[b]{0.33\textwidth}
\includegraphics[width=\linewidth]{universe.jpg}
\caption{Universe 4}
\label{fig:d}
\end{subfigure}
\caption{Pictures of Galaxies}\label{fig:animals}
\end{figure}
\noindent Fig.\ref{fig:animals} shows all the images. Fig.\ref{fig:a} shows universe 1 and Fig.\ref{fig:c} shows universe 3.
\end{document}
Exercise 10 : Sections
Sections and subsections can be created as shown below. We can recursively go down to 4-5 levels of subsections with the default settings.
\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\begin{document}
\section{Main Heading 1}\label{heading1}
content 1
\subsection{Sub Heading 2}
sub content
\subsubsection{Sub sub Heading 3}\label{experiment}
sub sub content
\section{Main Heading 2}
content 2
The introduction section \ref{experiment} deals with the setup.
\end{document}
Exercise 11 : Lists and Enumeration
Creating bullet-pointed lists and numbered lists are very easy as shown below.
\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\begin{document}
\begin{itemize}
\item Item1
\item Item2
\end{itemize}
\begin{enumerate}
\item Task 1
\item Task 3
\item Task 2
\end{enumerate}
\end{document}
Exercise 11 A : Lists and Enumeration
\documentclass{article}
\usepackage{enumerate}
\begin{document}
\begin{enumerate}[I]
\item item 1
\item item 2
\end{enumerate}
\begin{enumerate}[i]
\item item 3
\item item 4
\item item 5
\end{enumerate}
\end{document}
Exercise 12 : Equations
Mathematical expressions can be written inline by writing the expression in between two ‘$’ symbols. One of the biggest plus points of LaTeX is the easiness of writing any complex math equation intuitively.
\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\begin{document}
In physics, the mass-energy equivalence is stated
by the equation $E=mc^2$, discovered in 1905 by Albert Einstein.
\begin{equation}
y = mx+c
\end{equation}
\begin{equation}
y = m_{ac}+m_b
\end{equation}
\end{document}
Exercise 12 A : Equations
We can write more complicated equations by cascading different functionalities
\begin{equation}
E = mc^2
\end{equation}
\begin{equation}
F = G \frac{m_1m_2}{r^2}
\end{equation}
\begin{equation}
\binom{n}{k} = \frac{n!}{k!(n-k)!}
\end{equation}
\begin{equation}
\frac{\partial^2 u}{\partial t^2} = c^2 \frac{\partial ^2 u}{\partial x^2}
\end{equation}
\begin{equation}
P(x) = \frac{1}{\sigma\sqrt{2\pi}}e^{\frac{-(x-\mu)^2}{2\sigma^2}}
\end{equation}
Exercise 13 A : Hyperlink
Adding the ‘hyperref’ package makes the digital document easier to navigate across sections and any URLs mentioned in the document.
\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{hyperref}
\hypersetup{
colorlinks=true,
linkcolor=blue,
urlcolor=blue,
citecolor=blue
}
\begin{document}
\section{Main Heading 1}\label{heading1}
content 1
\subsection{Sub Heading 2}
sub content
\subsubsection{Sub sub Heading 3}\label{experiment}
sub sub content
\section{Main Heading 2}
content 2
The introduction section \ref{experiment} deals with the setup.
\end{document}
Exercise 13 B : Hyperlink and URL
\documentclass{article}
\usepackage{hyperref}
\begin{document}
\href{http://www.google.com}{Click Here}
\newline
\url{http://www.google.com}
\newline
\href{mailto:sajilck@gmail.com}{sajilck@gmail.com}
\end{document}
Exercise 14 : Table
Creating tables is the only thing that I felt harder in LaTeX. The good news is that we can use free tools like https://tablesgenerator.com/ and graphically create any table with contents and get the LaTeX source code.
\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[table,xcdraw]{xcolor}
\begin{document}
\begin{table}[]
\centering
\begin{tabular}{lllll}
\cellcolor[HTML]{FFCCC9}1 & \cellcolor[HTML]{FFCCC9}2 & \cellcolor[HTML]{FFCCC9}3 & & \\
\cellcolor[HTML]{38FFF8}4 & \cellcolor[HTML]{38FFF8}4 & \cellcolor[HTML]{38FFF8}5 & & \\
& & & & \\
& & & &
\end{tabular}
\caption{Some numbers}
\label{tab:numbers}
\end{table}
Table \ref{tab:numbers} shows some data.
\end{document}
Exercise 15 : Footnotes
Creating footnotes is easy with the ‘\footnote{insert your footnote here}’ command.
\documentclass[11pt,oneside,onecolumn]{article}
%\renewcommand{\baselinestretch}{1.5}
\usepackage[utf8]{inputenc}
\begin{document}
\section{Introduction}
Lorem \footnote{First word of introduction} ipsum dolor sit amet, consectetur adipiscing elit. Nam nunc ligula, tincidunt id diam quis, dictum tincidunt libero. Sed semper dolor ut neque vestibulum ornare. Aenean eget sapien efficitur, maximus odio a, ornare orci. Quisque nec luctus odio, et dictum massa. Nullam non libero eros. Aenean tincidunt ante et libero condimentum consectetur. Etiam ut ante non mauris egestas viverra sit amet ullamcorper justo. Pellentesque nibh velit, ornare non molestie quis, vehicula vitae lacus.
\section{Theory}
Fusce \footnotemark \footnotetext{First word in theory section} ac venenatis tellus. Aliquam ac eleifend tortor. Mauris sapien tortor, vulputate at lacinia nec, tincidunt et leo. Aliquam erat volutpat. Donec rutrum consectetur lacinia. Morbi eu nisl justo. Sed sagittis molestie justo, eu venenatis tellus lacinia sed.\\
\noindent Maecenas iaculis purus vitae enim dapibus, condimentum dapibus massa feugiat. Praesent cursus sem quis mattis ornare. Donec a vulputate orci. Fusce hendrerit, odio id finibus egestas, leo nunc fermentum sem, non pharetra ipsum felis ac elit. Phasellus ultrices bibendum leo, at posuere tellus feugiat id. Nunc vitae enim sed est malesuada fermentum quis sit amet ex. Etiam sit amet mauris vel augue tincidunt commodo non quis nisi. Quisque a nisi risus. Quisque id ultricies tellus, vel venenatis justo. Pellentesque non eros ut mauris feugiat eleifend. Suspendisse varius rutrum ante, eu euismod arcu mattis sed. Vestibulum egestas leo nisi, sed ultrices velit auctor vel.
\section{Conclusion}
Ut non mauris faucibus, aliquet turpis et, tincidunt enim. Curabitur auctor est id sapien gravida aliquam. Cras convallis elementum varius. Fusce nec luctus felis. Mauris a massa vel erat tristique volutpat. Donec tortor nunc, bibendum auctor accumsan quis, euismod vel mauris. Nunc justo odio, faucibus vel accumsan.
Ut non mauris faucibus, aliquet turpis et, tincidunt enim. Curabitur auctor est id sapien gravida aliquam. Cras convallis elementum varius. Fusce nec luctus felis. Mauris a massa vel erat tristique volutpat. Donec tortor nunc, bibendum auctor accumsan quis, euismod vel mauris. Nunc justo odio, faucibus vel accumsan.
\end{document}
Exercise 16 : Headers and Footers
Creating headers and footers is done with the ‘fancyhdr’ package. ‘\lhead{}’ represents the header on the left side and ‘\rfoot{}’ represents the footer on the right side of the page.
\documentclass{article}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\rhead{\LaTeX}
\lhead{Tutorial}
\rfoot{\thepage}
\lfoot{FDP}
\usepackage{graphicx}
\begin{document}
\section{Introduction}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam nunc ligula, tincidunt id diam quis, dictum tincidunt libero. Sed semper dolor ut neque vestibulum ornare. Aenean eget sapien efficitur, maximus odio a, ornare orci. Quisque nec luctus odio, et dictum massa. Nullam non libero eros. Aenean tincidunt ante et libero condimentum consectetur. Etiam ut ante non mauris egestas viverra sit amet ullamcorper justo. Pellentesque nibh velit, ornare non molestie quis, vehicula vitae lacus. The sunrise picture is shown in Figure \ref{fig:universe}.
\begin{figure}[h!]
\centering
\includegraphics[width=0.5\textwidth]{photo.jpeg}
\caption{The Universe}
\label{fig:universe}
\end{figure}
semper dolor ut neque vestibulum ornare. Aenean eget sapien efficitur, maximus odio a, ornare orci. Quisque nec luctus odio, et dictum massa. Nullam non libero eros. Aenean tincidunt ante et libero condimentum consectetur. Etiam ut ante non mauris egestas viverra sit amet ullamcorper justo. Pellentesque nibh velit, ornare non molestie quis, vehicula vitae lacus.\\
semper dolor ut neque vestibulum ornare. Aenean eget sapien efficitur, maximus odio a, ornare orci. Quisque nec luctus odio, et dictum massa. Nullam non libero eros. Aenean tincidunt ante et libero condimentum consectetur. Etiam ut ante non mauris egestas viverra sit amet ullamcorper justo. Pellentesque nibh velit, ornare non molestie quis, vehicula vitae lacus.\\
Nullam non libero eros. Aenean tincidunt ante et libero condimentum consectetur. Etiam ut ante non mauris egestas viverra sit amet ullamcorper justo. Pellentesque nibh velit, ornare non molestie quis, vehicula vitae lacus. Nullam non libero eros. Aenean tincidunt ante et libero condimentum consectetur. Etiam ut ante non mauris egestas viverra sit amet ullamcorper justo.
\end{document}
Exercise 17 : ToC, List of Figures & Tables
Once we have enough content, sections, tables, and figures, it is easy to generate a table of contents, list of figures, and list of tables.
\documentclass{article}
\usepackage[table,xcdraw]{xcolor}
\usepackage{graphicx}
\begin{document}
\tableofcontents
\pagebreak
\listoffigures
\pagebreak
\listoftables
\pagebreak
\section{Introduction}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam nunc ligula, tincidunt id diam quis, dictum tincidunt libero. Sed semper dolor ut neque vestibulum ornare. Aenean eget sapien efficitur, maximus odio a, ornare orci. Quisque nec luctus odio, et dictum massa. Nullam non libero eros. Aenean tincidunt ante et libero condimentum consectetur. Etiam ut ante non mauris egestas viverra sit amet ullamcorper justo. Pellentesque nibh velit, ornare non molestie quis, vehicula vitae lacus. The sunrise picture is shown in Figure \ref{fig:universe}.
\begin{figure}[h!]
\centering
\includegraphics[width=0.5\textwidth]{photo.jpeg}
\caption{The Universe}
\label{fig:universe}
\end{figure}
semper dolor ut neque vestibulum ornare. Aenean eget sapien efficitur, maximus odio a, ornare orci. Quisque nec luctus odio, et dictum massa. Nullam non libero eros. Aenean tincidunt ante et libero condimentum consectetur.
\section{Analysis}
Etiam ut ante non mauris egestas viverra sit amet ullamcorper justo. Pellentesque nibh velit, ornare non molestie quis, vehicula vitae lacus.\\
\begin{table}[h]
\centering
\begin{tabular}{lllll}
\cellcolor[HTML]{FFCCC9}1 & \cellcolor[HTML]{FFCCC9}2 & \cellcolor[HTML]{FFCCC9}3 & & \\
\cellcolor[HTML]{38FFF8}4 & \cellcolor[HTML]{38FFF8}4 & \cellcolor[HTML]{38FFF8}5 & & \\
& & & & \\
& & & &
\end{tabular}
\caption{Some numbers}
\label{tab:numbers}
\end{table}
semper dolor ut neque vestibulum ornare. Aenean eget sapien efficitur, maximus odio a, ornare orci. Quisque nec luctus odio, et dictum massa. Nullam non libero eros. Aenean tincidunt ante et libero condimentum consectetur. Etiam ut ante non mauris egestas viverra sit amet ullamcorper justo. Pellentesque nibh velit, ornare non molestie quis, vehicula vitae lacus.\\
Nullam non libero eros. Aenean tincidunt ante et libero condimentum consectetur. Etiam ut ante non mauris egestas viverra sit amet ullamcorper justo.
\end{document}
Exercise 18 : Abbreviations
‘\item[abbreviation]’ is used to create Abbreviations
\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[acronym, toc]{glossaries}
\begin{document}
\textbf{Abbreviations}
\newcommand{\abbrlabel}[1]{\makebox[3cm][l]{\textbf{#1}\ \dotfill}}
\newenvironment{abbreviations}{\begin{list}{}{\renewcommand{\makelabel}{\abbrlabel}}}{\end{list}}
\begin{abbreviations}
\item[ETA] Expected Time of Arrival
\item[LMS] Least Mean Square
\end{abbreviations}
\end{document}
Exercise 18 A : Epigraph
\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage{epigraph}
\begin{document}
\chapter{Introduction}
\epigraph{If something's important enough, you should try. Even if - the probable outcome is failure}{Elon Musk}
\end{document}
Exercise 19 : Inserting Code
You can insert code written in any language by loading it from a file very easily.
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{minted}
\begin{document}
\section{Reproducible Research}
The code used for the study is given below.
\inputminted{python}{python.py}
\end{document}
Exercise 20 A : Citation and Bibliography
Reference management is easy once you have the BibTeX meta information of articles you would like to cite as a file (e.g. references.bib). The biblatex package is used for this purpose. You cite an article from your list using the ‘\cite{label}’ or ‘\parencite{label}’ command.
\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[a4paper,width=145mm,top=30.5mm, bottom=30.5mm, bindingoffset=6mm]{geometry}
\usepackage{graphicx}
\usepackage[backend=bibtex,sorting=none]{biblatex}
\addbibresource{references.bib}
\begin{document}
\section{Introduction}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam nunc ligula, tincidunt id diam quis, dictum tincidunt libero. Sed semper dolor ut neque vestibulum ornare. Aenean eget sapien efficitur, maximus odio a, ornare orci \cite{paperRicardo2020}. Quisque nec luctus odio, et dictum massa. Nullam non libero eros. Aenean tincidunt ante et libero condimentum consectetur. Etiam ut ante non mauris egestas viverra sit amet ullamcorper justo. Pellentesque nibh velit, ornare non molestie quis, vehicula vitae lacus. The sunrise picture is shown in Figure \ref{fig:universe}.
\begin{figure}[h!]
\centering
\includegraphics[width=0.5\textwidth]{photo.jpeg}
\caption{The Universe}
\label{fig:universe}
\end{figure}
semper dolor ut neque vestibulum ornare. Aenean eget sapien efficitur, maximus odio a, ornare orci. Quisque nec luctus odio, et dictum massa. Nullam non libero eros. Aenean tincidunt ante et libero condimentum consectetur. Etiam ut ante non mauris egestas viverra sit amet ullamcorper justo. Pellentesque nibh velit, ornare non molestie quis, vehicula vitae lacus.\\
semper dolor ut neque vestibulum ornare. Aenean eget sapien efficitur, maximus odio a, ornare orci. Quisque nec luctus odio, et dictum massa. Nullam non libero eros. Aenean tincidunt ante et libero condimentum consectetur. Etiam ut ante non mauris egestas viverra sit amet ullamcorper justo. Pellentesque nibh velit, ornare non molestie quis, vehicula vitae lacus.\\
Nullam non libero eros. Aenean tincidunt ante et libero condimentum consectetur. Etiam ut ante non mauris egestas viverra sit amet ullamcorper justo. Pellentesque nibh velit, ornare non molestie quis, vehicula vitae lacus. Nullam non libero eros. Aenean tincidunt ante et libero condimentum consectetur. Etiam ut ante non mauris egestas viverra sit amet ullamcorper justo.
\printbibliography
\end{document}
Exercise 20 B : Citation and Bibliography
Another example of citation in author-year format.
\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[a4paper,width=145mm,top=30.5mm, bottom=30.5mm, bindingoffset=6mm]{geometry}
\usepackage{graphicx}
\usepackage[backend=bibtex,style=alphabetic,
citestyle=authoryear]{biblatex}
\addbibresource{references.bib}
\begin{document}
\section{Introduction}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam nunc ligula, tincidunt id diam quis, dictum tincidunt libero. Sed semper dolor ut neque vestibulum ornare. Aenean eget sapien efficitur, maximus odio a, ornare orci \parencite{paperRicardo2020}. Quisque nec luctus odio, et dictum massa. Nullam non libero eros. Aenean tincidunt ante et libero condimentum consectetur. Etiam ut ante non mauris egestas viverra sit amet ullamcorper justo. Pellentesque nibh velit, ornare non molestie quis, vehicula vitae lacus. The sunrise picture is shown in Figure \ref{fig:universe}.
\begin{figure}[h!]
\centering
\includegraphics[width=0.5\textwidth]{photo.jpeg}
\caption{The Universe}
\label{fig:universe}
\end{figure}
semper dolor ut neque vestibulum ornare. Aenean eget sapien efficitur, maximus odio a, ornare orci. Quisque nec luctus odio, et dictum massa. Nullam non libero eros. Aenean tincidunt ante et libero condimentum consectetur. Etiam ut ante non mauris egestas viverra sit amet ullamcorper justo. Pellentesque nibh velit, ornare non molestie quis, vehicula vitae lacus.\\
semper dolor ut neque vestibulum ornare. Aenean eget sapien efficitur, maximus odio a, ornare orci. Quisque nec luctus odio, et dictum massa. Nullam non libero eros. Aenean tincidunt ante et libero condimentum consectetur. Etiam ut ante non mauris egestas viverra sit amet ullamcorper justo. Pellentesque nibh velit, ornare non molestie quis, vehicula vitae lacus.\\
Nullam non libero eros. Aenean tincidunt ante et libero condimentum consectetur. Etiam ut ante non mauris egestas viverra sit amet ullamcorper justo. Pellentesque nibh velit, ornare non molestie quis, vehicula vitae lacus. Nullam non libero eros. Aenean tincidunt ante et libero condimentum consectetur. Etiam ut ante non mauris egestas viverra sit amet ullamcorper justo.
\printbibliography
\end{document}
Exercise 21 : Presentation Slides
We can also create presentation slides using the beamer document class. Each slide starts with ‘\begin{frame}’ command.
\documentclass{beamer}
\mode<presentation> {
\title[Title of Talk}
\author{\textbf {Name}}
\date{Month Year}
\institute[University/Organization]
{Address\\
\medskip
\textit{email}
}
\begin{document}
\begin{frame}
\titlepage
\end{frame}
\begin{frame}
\frametitle{Slide1}
\end{frame}
\end{document}
Exercise 22 : Splitting Files
It is recommended to organize your LaTeX source code by splitting it across multiple files. We have seen similiar example of inserting source code from another file. We can use the ‘\input{filename}’ to read and insert code from another file to the main document.
\documentclass{article}
\usepackage[utf8]{inputenc}
\begin{document}
\input{Section1/Section1.tex}
\end{document}
Conclusion
These examples show the essential usage one needs to know to create documents in LaTeX. Please keep in mind that, it is not possible to remember every LaTeX command. As users, we just need to get familiar with its usage and should be able to look up and create source code from documentation. The Overleaf documentation https://www.overleaf.com/learn covers a lot of additional topics with examples.
👍🏻