You are on page 1of 18

LaTeX Tutorial

Hamza Ahmed Mir


01-03-2015

Contents
1 Lesson 1
1.1 Preamble . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.1.1 Latex Commands For Beginners . . . . . . . . . . . . .
1.1.2 Commands For Numbering Format . . . . . . . . . . .

2
2
2
2

2 Lesson 2
2.1 Useful Commands for Hierarchy . . . . . . . . . . . . . . . . .

3
3

3 Lesson 3
3.1 Equations and Packages . . . . . . . . . . . . . . . . . . . . .

4
4

4 Lesson 4
4.1 Some
4.2 Some
4.2.1
4.2.2
4.2.3
4.2.4

.
.
.
.
.
.

5
5
5
5
5
6
7

5 Lesson 5
5.1 Adding Image in LaTex . . . . . . . . . . . . . . . . . . . . .
5.2 Commands Used for Figure . . . . . . . . . . . . . . . . . . .
5.3 Summary of Commands . . . . . . . . . . . . . . . . . . . . .

8
8
8
8

More Math Properties . . . . . . . . .


More Math Properties . . . . . . . . .
The equation and align environment
Use of Integrals and Fractions . . . .
Matrices . . . . . . . . . . . . . . . .
Summary of Lesson 4 . . . . . . . . .

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

6 Lesson 6
10
6.1 Adding Table of Content . . . . . . . . . . . . . . . . . . . . . 10
6.2 Adding List of Figures and Tables . . . . . . . . . . . . . . . . 10
7 Lesson 7
7.1 Bibliography . . . . . . . . . . . .
7.2 Reference . . . . . . . . . . . . .
7.2.1 Entry Types . . . . . . . .
7.2.2 Sequence of Commands for
7.2.3 Summary of Commands .

.
.
.
.
.

11
11
11
11
12
12

8 Lesson 8
8.1 Tabular Environment . . . . . . . . . . . . . . . . . . . . . . .
8.2 Another Table . . . . . . . . . . . . . . . . . . . . . . . . . . .
8.3 Summary of Table Commands . . . . . . . . . . . . . . . . . .

14
14
14
14

. . . . . . . .
. . . . . . . .
. . . . . . . .
Bibliography
. . . . . . . .

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

List of Figures
1

Sample LaTex Image . . . . . . . . . . . . . . . . . . . . . . .

List of Tables
1
2
3

Caption for the table. . . . . . . . . . . . . . . . . . . . . . . . 10


Caption for the table. . . . . . . . . . . . . . . . . . . . . . . . 14
Caption for the table. . . . . . . . . . . . . . . . . . . . . . . . 14

Introduction
This is just a quick latex tutorial.
Summary of LaTeX Commands
Commands
Description
\documentclass{Option} Define Type of Document
\title{Document Name}
Name of Document
\maketitle
Title Page
\huge
Font size
\begin {center}
Formatting text to Center

Lesson 1

1.1

Preamble

A document has a preamble and document part The document environment


must be defined. Anything you Write before begin command is known as
preamble. You generally write title, date and author of the document in
preamble
1.1.1

Latex Commands For Beginners

Generally, Commands begin with a backslash and commands that define


environments have a begin and end tag.
Useful Commands Some Commands that are used at the beginning of
every document are \documentclass,\title, \date, \author and \begin.
Options for different commands are defined inside curly brackets.
1.1.2

Commands For Numbering Format

The main command for selecting a particular type of numbering format is:
\pagenumbering{Option}
Options for pagenumbering Commands are:
1. gobble - no numbers
2. arabic - arabic numbers
3. roman - roman numbers

2
2.1

Lesson 2
Useful Commands for Hierarchy

LaTeX uses the commands section, subsection and subsubsection to define


sections in your document.
It also uses commands paragraphs and subparagraphs to define paragraph
with title in your document.
Difference between Section and Paragraph The sections will have
successive numbers and appear in the table of contents Paragraphs are not
numbered and thus dont appear in the table of contents

3
3.1

Lesson 3
Equations and Packages

LaTeX uses special environment for Math equation by using beginequation


command. usepackage command is used for package with name of package
inside curly brackets. amsmath package is used to include a special equation*
environment which doesnt give equations number.
f (x) = x2
Packages Benefits Packages add new functions to LaTeX All packages
must be included in the preamble Packages add features such as support for
pictures, links and bibliography

Lesson 4

4.1

Some More Math Properties

LaTeX also uses inline command for equations and symbols by using $ sign
before and after math symbols.
Example This formula f (x) = x2 is an example.

4.2

Some More Math Properties

The equation and align environment


Fractions and more
Matrices
Brackets in math mode - Scaling
4.2.1

The equation and align environment

Simple Equations using \begin{equation*} command.


1+2=3
1=32
Aligned Equations using \begin{align*}
1+2=3
1=32
Note: The asterisk (e.g. equation ) only indicates, that equations shouldnt
be numbered.
4.2.2

Use of Integrals and Fractions

\frac{num}{den} - for fractions


\inta b - for Integral Symbol \sqrt - for Square Root Symbol

Note: Nested commands can be used such as: \frac{1}{\sqrt{x}}


f (x) = x2
1
g(x) =
Zx

F (x) =
b

1 3
x
3

1
G(x) =
x
4.2.3

Matrices

First define the Matrix environment by using command \begin{matrix}




0 1
1 0
Options for matrix command
matrix: unbracketed matrix
pmatrix: matrix surrounded by parentheses
bmatrix: matrix surrounded by square brackets
vmatrix: matrix surrounded by single vertical lines
Vmatrix: matrix surrounded by double vertical lines
Another way of inserting brackets is to use \left and \right command. This
does also work for parentheses and braces and is not limited to matrices.
Example Following Output fraction is an example for adding brackets.


1

x
Note: Matrices only work within math environments, so use
\begin{align} command before defining matrix or using \frac{num}{den}
command otherwise LaTex compiler will give error.

4.2.4

Summary of Lesson 4

LaTeX is a powerful tool to typeset math


Embed formulas in your text by surrounding them with dollar signs $
The equation environment is used to typeset one formula
The align environment will align formulas at the ampersand & symbol
Single formulas must be separated with two backslashes \\
Use the matrix environment to typeset matrices
Scale parentheses with \left{\right} automatically
All mathematical expressions have a unique command with unique syntax
Notable examples:
\int a b for integral symbol
\frac {u}{v} for fractions
\sqrt{x} for square roots
Characters for the greek alphabet and other mathematical symbols
such as \lambda

Lesson 5

5.1

Adding Image in LaTex

LaTeX index all pictures automatically and tag them with successive numbers
when using the figure environment and the graphicx package.

Figure 1: Sample LaTex Image

5.2

Commands Used for Figure

Main command for adding figure is \begin{figure}[Options]. For Figure Environment, different options Include:
h (here) - same location
t (top) - top of page
b (bottom) - bottom of page
p (page) - on an extra page
! (override) - will force the specified location
The float package \usepackage{float} allows to set the option to [H],
which is even stricter than [h!].

5.3

Summary of Commands

\begin{figure}[h!]- Figure Environment with Image added at same location


\includegraphics[width=\linewidth]{Image/SampleLatexImage.png} To include a figure
\caption{Sample LaTex Image} - text shown below the image
8

\label{Sample Image} - Useful if we want to refer to our figure in our


document. You can use the \ref command to refer to the figure (marked
by label) in your text and it will then be replaced by the correct number.
Figure 1 shows a sample LaTex Image.

6
6.1

Lesson 6
Adding Table of Content

Table of content can be generated using \tableofcontents.

6.2

Adding List of Figures and Tables

Create lists of your figures and tables with \listoffigures and \listoftables.
Table 1: Caption for the table.
1 2 3
a b c

Note: Always compile twice to see the changes.

10

Lesson 7

7.1

Bibliography

A .bib file will contain the bibliographic information of our document. Use
any standard bibtex generator to create .bib file. Lets begin on how to add
a single book in the bibliography.
Use \cite {reference} command to cite the reference embedded in text.
Use \bibliography{filename} and \bibliographystyle{stylename} for selecting a particular style of reference
Example: Random Citation [1] embedded in text

7.2

Reference

Make a separate .bib file using the reference details such as author, title,
publisher and year of publishing.
The format of a typical .bib file is as follows:
Entry type{unique name of reference ,
AUTHOR = Author Name,
TITLE = Title of Book,
PUBLISHER = Name of Publisher,
YEAR = Year of Publishing,
}
Note: entry type tells BibTeX that the information stored here is about a
particular entry type.
7.2.1

Entry Types

Besides the entry types shown in the example (i.e book) there are a lot more
such as
article - Article from a magazine or journal
book - A published book
booklet - A work that is printed but have no publisher or sponsoring
institution.
conference - An article in a conference proceedings
11

inbook - A part of a book (section, chapter and so on)


incollection - A part of a book having its own title
inproceedings - An article in a conference proceedings
manual - Technical documentation
masterthesis - A Masters thesis
misc - Something that doesnt fit in any other type
phdthesis - A PhD thesis
proceedings - The same as conference
techreport - Report published by an institution
unpublished - Document not formally published, with author and title
7.2.2

Sequence of Commands for Bibliography

For inserting bibliography using BibTex file, use the following sequence of
commands
PdfLaTeX
Bibtex
PdfLaTeX
PdfLaTeX
Pdf Viewer
7.2.3

Summary of Commands

Generate a bibliography with BibTeX and BibLaTeX


First define a .bib file using:
\bibliography{BIB FILE NAME} (do not add .bib)
For BibTeX put the \bibliography statement in your document, for
BibLaTeX in the preamble
BibTeX uses the \bibliographystyle command to set the citation style
12

BibLaTeX chooses the style as an option like:


\usepackage [backend=bibtex,style=verbose-trad2] {biblatex}
BibTeX uses the \cite command, while BibLaTeX uses the \autocite
command
The \autocite command takes the page number as an option:
\autocite [NUM] {}

13

Lesson 8

8.1

Tabular Environment
Table 2: Caption for the table.
1 2 3
a b c

8.2

Another Table
Table 3: Caption for the table.
Some
actual
content
prettifies
as
using

8.3

the
well
the

content
as
booktabs package

Summary of Table Commands

LaTeX offers the table and tabular environment for table creation
The table environment acts like a wrapper for the tabular similar to
the figure environment.
Alignment and vertical separators are passed as an argument to the
tabular environment (e.g. \begin{tabular}{l|c||r})
Its possible to align the content left (l), centered (c) and right (r),
where the number of alignment operators has to match the desired
number of columns
The columns can be separated by adding |in between the alignment
operators
Rows can be separated using the \hline command and columns using
the ampersand & symbol
The newline \\operator indicates the end of a row
Its possible to refer to tables using \ref and \label
14

References
[1] H. A. Mir, LaTex Tutorial. Hamza & Co., 2016.

15