You are on page 1of 76

Introduction to LATEX

By: Fikreselam Gared(PhD)

Faculty of Electrical and Computer Engineering

October 28,2017

Fikreselam G. Title: Introduction to LATEX October 28,2017 1 / 76


Outline

1 Introduction
2 LATEX Versus Word Processor
3 Step to Install the software
4 Main Commands for the document Environment
5 Special Characters of LaTex
6 Title and sectioning commands
7 Mathematical Expressions
8 Figures and Tables
9 Reference/Bibliography

Fikreselam G. Title: Introduction to LATEX October 28,2017 2 / 76


Introduction

LATEX is pronounced lay-tech or lah-tech,

LATEX is a document preparation system and document markup


language.

TeX is a program for typesetting text and mathematical formulas,


originally written by Prof. Knuth at Stanford around 1978.

Fikreselam G. Title: Introduction to LATEX October 28,2017 3 / 76


LaTeX is a user interface for TEX, designed by Leslie Lamport at
Digital Equipment Corporation (DEC) in 1985.

High level language for TeX

Run LaTeX to generate output and make modifications

Fikreselam G. Title: Introduction to LATEX October 28,2017 4 / 76


LATEX is a typesetting system that is very suitable for producing
scientific and mathematical documents of high typographical
quality.
LATEX contains features for typesetting:
X Journal articles, technical reports, books, slide presentations,
X control over large documents containing sectioning, cross
sectioning, cross-references, tables and figures,
X typesetting of complex mathematical formulas, automatic
generation of bibliographies and indexes and so on

Fikreselam G. Title: Introduction to LATEX October 28,2017 5 / 76


LATEX Versus Word Processor

High typeset quality

Easy to include math formulas

Source file format is not bounded to a particular OS or platform

Latex implementations exists for all platforms (DOS, Windows,


Unix,..)

Complex structures such as footnotes, table of contents, and


bibliographies can be generated easily.

Good for large documents

Fikreselam G. Title: Introduction to LATEX October 28,2017 6 / 76


Figure 1 : Latex Versus Word

Fikreselam G. Title: Introduction to LATEX October 28,2017 7 / 76


Fikreselam G. Title: Introduction to LATEX October 28,2017 8 / 76
Few challenges

Requires remembering some commands

The design of a whole new layout is difficult and takes a lot of time.
Templates help you here

Fikreselam G. Title: Introduction to LATEX October 28,2017 9 / 76


Step to Install the software

The compiler (MikeTeX) and the text editor (Texmaker ) must be


installed for WOS.

MikTeX is a typesetting system for the Windows.

MacTex is a typesetting system for the Mac OS.

You can download the Miketex from


http://miktex.org/download and

you can download the Texmaker from


http://www.xm1math.net/texmaker.

Fikreselam G. Title: Introduction to LATEX October 28,2017 10 / 76


Figure 2 : MikTex

Fikreselam G. Title: Introduction to LATEX October 28,2017 11 / 76


Figure 3 : MacTex

Fikreselam G. Title: Introduction to LATEX October 28,2017 12 / 76


Figure 4 : Texmaker

Fikreselam G. Title: Introduction to LATEX October 28,2017 13 / 76


Figure 5 : Texmaker

Fikreselam G. Title: Introduction to LATEX October 28,2017 14 / 76


Figure 6 : online

Fikreselam G. Title: Introduction to LATEX October 28,2017 15 / 76


Figure 7 : Latex File

Fikreselam G. Title: Introduction to LATEX October 28,2017 16 / 76


The new opened Texmaker is shown in Fig. 8

Figure 8 : New Texmaker

Fikreselam G. Title: Introduction to LATEX October 28,2017 17 / 76


The new opened Texmaker which includes the pdf viewer is shown
below

Figure 9 : New Texmaker

Fikreselam G. Title: Introduction to LATEX October 28,2017 18 / 76


Structure : the place where you see the structure of the content of
your latex document

Main body: the place where you see the whole content of your
document

Log part: the place where you see the report of the document
after compilation respectively

Fikreselam G. Title: Introduction to LATEX October 28,2017 19 / 76


Figure 10 : configuration

For MacTex:-click texmaker then Preferences


Fikreselam G. Title: Introduction to LATEX October 28,2017 20 / 76
Files generated when you run the tex file are
.tex
.pdf
. dvi (device independent
.rtf (rich text format
.ps (post script)
.gz (zipped folder)
log
etc

Better to put tex file inside folder

Fikreselam G. Title: Introduction to LATEX October 28,2017 21 / 76


Figure 11 : Sequence of commands for generating LATEXdocument

Fikreselam G. Title: Introduction to LATEX October 28,2017 22 / 76


Main Commands for the document Environment

\documentclass [ option ] { style } in which you decide the size


of your font and the type of your document as it can be either of an
article, a report, a book, beamer and so on
\begin { document } for upper limits of your document. and
\end { document } for lower limits of your document.
12pt and 11pt are 20 % and 10 % larger than 10pt respectively

Fikreselam G. Title: Introduction to LATEX October 28,2017 23 / 76


Figure 12 : Document Environment

Fikreselam G. Title: Introduction to LATEX October 28,2017 24 / 76


Special characters of Matlab

[ ] used to form vectors and matrices

{ } used in cell array assignment statement

= used to assign statements

’ matrix transpose

ˆ caret used for element wise power

% denotes a comment

Fikreselam G. Title: Introduction to LATEX October 28,2017 25 / 76


Special Characters of LaTex

$, {, &, }, #, %, , X, \, |, etc are special characters


$ \$
{ \{
} \}
& \&
# \#
% \%
\
X \checkmark
\ \textbackslash
| \textbar

Fikreselam G. Title: Introduction to LATEX October 28,2017 26 / 76


Errors

LaTex prints an error message on your messages/log and then


stops and waits for you to take some action.
Follow error indicator which begin by ! and error locator

Fikreselam G. Title: Introduction to LATEX October 28,2017 27 / 76


Title and sectioning commands

To create title
\title { Introduction to Latex for Fifth year students }
\author { Fikreselam G.}
\date { \today }
\maketitle

Fikreselam G. Title: Introduction to LATEX October 28,2017 28 / 76


Sectioning commands
\part {....}
\chapter {....} under report style
\section {....} or \section* {....}
\subsection {....} or \subsection* {....}
\subsubsection {....}
\paragraph {....}
\subparagraph {....}
you can fix the numbering of your section by
\setcounter{secnumdepth}{3} and \setcounter {tocdepth} {3}
To add table of content
\tableofcontents

Fikreselam G. Title: Introduction to LATEX October 28,2017 29 / 76


font

Bold \textbf {...}

Underline \underline {...}

Italic \textit {... }

Capital letter \textsc {... }

font size: technology using \large{technology }

font size technology using \Large{technology }

font size technology using \LARGE{technology}

font size technology using \huge{technology}


font size technology using \Huge {technology}
Fikreselam G. Title: Introduction to LATEX October 28,2017 30 / 76
font size: technology using \normalsize {technology }

font size technology using \small {technology }

font size technology using \footnotesize {technology}

font size technology using \scriptsize{technology}

font size technology using \tiny {technology}

Fikreselam G. Title: Introduction to LATEX October 28,2017 31 / 76


Horizontal and Vertical Space

The commands \hspace { } and \vspace { } leave horizontal


and vertical space in your text.

LaTeX removes horizontal space that comes at the end of a line


(after you break the line). If you don’t want LaTeX to remove this
space, include the optional * argument. Then the space is never
removed. Like: \hspace* { }

LaTeX removes vertical space that comes at the end of a page. If


you don’t want LaTeX to remove this space, include the optional *
argument.

Fikreselam G. Title: Introduction to LATEX October 28,2017 32 / 76


units

Fikreselam G. Title: Introduction to LATEX October 28,2017 33 / 76


Line and Page Breaking

In special cases it might be necessary to order LATEX to break a line


using:-

\\ or

\newline to starts a new line without starting a new paragraph.


and

\newpage starts a new page.

two break space or double enter will create paragraph separation.

Fikreselam G. Title: Introduction to LATEX October 28,2017 34 / 76


Lists

In the itemize environment , the start of each item is given a


marker
\begin {itemize}
\end {itemize}
In the enumerate environment, each item is marked by a number
\begin {enumerate}
\end {enumerate }
Example
BIT
1 FCWE
2 FECE
Fikreselam G. Title: Introduction to LATEX October 28,2017 35 / 76
Mathematical Expressions

A mathematical expression usually consists of expressions like:

superscripts
subscripts
fractions, roots
matrices
integrals
derivatives
summations and products
functions like trigonometric & logarithmic functions
Greek letters & symbols and others
Fikreselam G. Title: Introduction to LATEX October 28,2017 36 / 76
Mathematical equations within a paragraph are entered between $
and $:
Example: C 2 = A2 + B 2 is obtained by the following command
$ C ˆ2=A ˆ 2+B ˆ2)$
\begin{equation} and \end {equation} is the basic equation
command to write in new line with equation number.
Example:
C 2 = A2 + B 2 (1)

use \tag { } command with proper package to label your our own
tag. Example:

C 2 = A2 + B 2 (a)
Fikreselam G. Title: Introduction to LATEX October 28,2017 37 / 76
several line equations

\begin {eqnarray}
y & =& x+ 3 \theta- 1.5 \theta \nonumber \\
& = & x+ 1.5 \theta
\end {eqnarray}

y = x + 3θ − 1.5θ

= x + 1.5θ (2)

Fikreselam G. Title: Introduction to LATEX October 28,2017 38 / 76


Superscript and subscript

use $X 2$ to write X2

use $Z {x + y}$ to write Zx+y

use $X ∧ 2$ to write X 2

use $Z ∧ {x + y}$ to write Z x+y

Fikreselam G. Title: Introduction to LATEX October 28,2017 39 / 76


Fraction, Trigonometric & logarithmic function and
Roots

The command for fraction is $ \frac { numerator }{ denominator}


numerator
$ to get denominator .
sin(θ)
write tan(θ) = cos(θ)
W +X
write Y +Z
 
(yj −(−1)v̂j )2

write loge √ 1 − exp
2πσ 2 2σ 2
p
3
use $ \sqrt[3] { \sin ∧ 2 + \cos ∧ 2 $ } to write sin2 + cos2

Fikreselam G. Title: Introduction to LATEX October 28,2017 40 / 76


Matrix /Array

$\left ( \begin{array}{ccc}
1 & 2&3 \\
4 & 5&6 \\
7 & 8&9 \\
\end{array} \right)$
gives
 
1 2 3
 
 
 4 5 6 
 
7 8 9

Fikreselam G. Title: Introduction to LATEX October 28,2017 41 / 76



−1 2 3



−4 5 −6 (3)




7 8 −9
 
1 2 3
 
(4)
 
 4 5 6 
 
7 8 9
 
A B C 0 1 2 3
 
 D E F 4 5 6 7
 




 (5)
 0 1 2 3 A B C D 
 
4 5 6 7 E F G H

Fikreselam G. Title: Introduction to LATEX October 28,2017 42 / 76


Different Operators and Accents
P6
Summation: Use $ \sum 0 ∧ 6 $ to write 0
R6
Integral: Use $ \int 0 ∧ 6 $ to write 0
Product: Use$ \prod 0 ∧ 6 $ to write 60
Q

Absolute Value: Use $ |X| $ to write |X|


Hat: Use $ \hat{x} $ to write x̂
Bar: Use$ \bar{x} $ to write x̄
Tilde: Use $ \tilde{x} $ to write x̃
Vector: Use $ \vec{x} $ to write ~x
n

Binomials: Use$ \binom{n}{k} $ to write k
Text in a formula: Use $ \mbox { text in a formula} $ to write
text in a formula
Fikreselam G. Title: Introduction to LATEX October 28,2017 43 / 76

α1 − α2 ω1 − ω2




N −1 

x1 + β y X 
1

(yj )2

β = ± v ≥ ln √ − (6)
u
2πσ 2 2σ 2
u l1 m1 m1 n1

j=0
u
t + 
l2 m2 nk

ζ

Fikreselam G. Title: Introduction to LATEX October 28,2017 44 / 76


Few Packages :- \usepackage { package name}

amsmath: Is the most important package introduces several


improvements for math environment. It contains the advanced
math expressions for LATEX. Example:- differential, tag
AMS: American Mathematical Society
amssymb: adds new symbols in to be used in math mode

Fikreselam G. Title: Introduction to LATEX October 28,2017 45 / 76


amscd: used to produce rectangular diagram and support plain
labelled arrows in which its arrows do stretch to match labels.

geometry: to adjust the margins of pages. example: \usepackage


[a4paper]{geometry }

graphicx: this package introduces the \includegraphics{ }


command, which is needed for inserting figures.

color: used to provides a way to use colors

microtype: improves the spacing between words and letters. It


does a lot more and most people will not notice the difference.

float: improve interface for floating object such as figures and


tables.
Fikreselam G. Title: Introduction to LATEX October 28,2017 46 / 76
Figures

Command for Figure is \includegraphics [option] {file}. where


Option can be:

height to set the height of the graphics.

width to set the width of the graphics.

scale Scale factor for the graphic (specifying scale=2 makes the
graphic twice as large as its natural size).

angle which specifies the angle of rotation, in degrees, with a


counter-clockwise rotation being positive.

Fikreselam G. Title: Introduction to LATEX October 28,2017 47 / 76


\begin {figure}[H]
\begin {center}
\includegraphics[height=7cm, width=10cm]{poly.png}
\caption {poly campus.}
\label {fig:poly}
\end {center}
\end {figure}

Fikreselam G. Title: Introduction to LATEX October 28,2017 48 / 76


The optional argument [placement] determines where LaTeX will
try to place your figure. There are four places where LaTeX can
possibly put a float:
h (Here) - at the position in the text where the figure environment
appears,
t (Top) - at the top of a text page,
b (Bottom) - at the bottom of a text page and
p (Page of floats) - on a separate float page, which is a page
containing no text, only floats.

Fikreselam G. Title: Introduction to LATEX October 28,2017 49 / 76


Figure 13 : post card.

Fikreselam G. Title: Introduction to LATEX October 28,2017 50 / 76


Figure 14 : poly campus.

Fikreselam G. Title: Introduction to LATEX October 28,2017 51 / 76


\begin {figure}[H]
\begin {center}
\includegraphics[height=4.5cm, width=6.5cm,angle=
45 ]{wisdom.png}
\caption {Wisdom Tower}
\label {fig:wisdom}
\end {center}
\end {figure}

Fikreselam G. Title: Introduction to LATEX October 28,2017 52 / 76


Figure 15 : Wisdom Tower

Fikreselam G. Title: Introduction to LATEX October 28,2017 53 / 76


\begin {figure}[H]
\includegraphics[ width=0.45 \linewidth]{poly.png}
\hfill
\includegraphics[ width=0.45 \linewidth]{wisdom.png}
\caption {poly and Wisdom}
\end {figure}

Fikreselam G. Title: Introduction to LATEX October 28,2017 54 / 76


Figure 16 : poly and wisdom

Fikreselam G. Title: Introduction to LATEX October 28,2017 55 / 76


To include caption to sub figures, use \usepackage { subcaption }
package at the preamble and use the following command:
\begin { subfigure }
\end { subfigure }

(a) poly (b) wisdom

Figure 17 : poly and wisdom: (a) poly (b) wisdom

Fikreselam G. Title: Introduction to LATEX October 28,2017 56 / 76


Tables

Command to create table :


\begin {table}
\end {table}

Argument to the tabular environment:


\begin { tabular } { |l |c |r}
\end {tabular}

Fikreselam G. Title: Introduction to LATEX October 28,2017 57 / 76


\begin {table}[H]
\centering
\caption {List of PG students}
\label {table }
\begin {tabular} { |c |l |r |l |c |} \hline
No & Name &Department & email address & signature \\ \hline
1&Helen & Civil &helen@yahoo.com & \\ \hline
2 &Robel & Mechanical &rob@gmail.com & \\ \hline
3 & John & Computer Science & john@hotmail.com & \\ \hline
\end {tabular}
\end {table}

Fikreselam G. Title: Introduction to LATEX October 28,2017 58 / 76


Table 1 : List of PG students

No Name Department email address signature


1 Helen Civil helen@yahoo.com fikre
2 Robel Mechanical rob@gmail.com
3 John computer Science john@hotmail.com

Fikreselam G. Title: Introduction to LATEX October 28,2017 59 / 76


use \listoffigures to add figures under list of figures.

use \listoftables to add tables under list of tables.

Use Fig. \ref {fig:figures label} to refer figures

Use Table \ref {table:table label } to refer tables

To add the word ”Figure” before the actual number in the list of
figures and to add the word ”Table” before the actual number in
the list of tables use:-
\usepackage {tocloft}
\renewcommand { \cftfigfont}{Figure }
\renewcomman{ \cfttabfont}{Table }

Fikreselam G. Title: Introduction to LATEX October 28,2017 60 / 76


Reference/Bibliography

Store all references in an external database (.bib)

There is auxiliary tool BibTex

BibTeX provides for the storage of all references in an external


database.

The bib file contains your database references. It contains entries,


the entries contain fields.

Fikreselam G. Title: Introduction to LATEX October 28,2017 61 / 76


Table 2 : Entry and Field of database

Entry Required fields Description


article author,title, journal, year article from a journal
book author,title, publisher, year book with publisher
booklet title book without publisher
inproceeding author,title, booktitle,year conference proceeding
manual title Technical documentation
masterthesis author,title, school, year Master thesis

Fikreselam G. Title: Introduction to LATEX October 28,2017 62 / 76


@article {referencename,
author={... },
title = {...},
journal= {...},
pages = {...},
year = {...}
}

Fikreselam G. Title: Introduction to LATEX October 28,2017 63 / 76


@book {referencename,
author={... },
title = {...},
publisher= {...},
year = {...}
}

Fikreselam G. Title: Introduction to LATEX October 28,2017 64 / 76


@inproceedings {referencename,
author={... },
book title = {...},
pages = {...},
year = {...}
}

Fikreselam G. Title: Introduction to LATEX October 28,2017 65 / 76


The database can be referenced in any LaTeX document.
\bibliographystyle {style}
\bibliography {referencename}

the styles can be : plain, usrt, abbrv, abstract, IEEEtran,alpha,


named and so on to sort by reference by author and other.

Citation made to any record that is contained within the file with
the command: \cite {referencename }

When a sequence of multiple citations are needed, you should


use \cite {referencename1, referencename2, referencename3,...}

Fikreselam G. Title: Introduction to LATEX October 28,2017 66 / 76


The numeric style of citation is quite common in scientific writing.
In other disciplines, the author-year style, e.g., (Bereket, 2016)
might be used

natbib package supports various format using


\usepackage[options]{natbib}

Fikreselam G. Title: Introduction to LATEX October 28,2017 67 / 76


When referring to a new reference in the bib-file:
Compile tex-file with LaTeX
Compile bib-file with BibTeX
Compile tex-file with LaTeX

you can insert website as a reference too

Fikreselam G. Title: Introduction to LATEX October 28,2017 68 / 76


For standard classes (article, book, report), adding
\usepackage[nottoc,numbib]{tocbibind} to your document
preamble to include reference in table of contents.

Omit numbib from the above to cancel chapter number of


reference from toc if you did not fix in the class of the template.

Fikreselam G. Title: Introduction to LATEX October 28,2017 69 / 76


1 Ethiopia University
1 Addis Ababa University
2 Bahir Dar University
1 Poly
2 peda
3 Yibab
4 zenzelema

Fikreselam G. Title: Introduction to LATEX October 28,2017 70 / 76


use \usepackage { tikz} and \usepackage { shapes, arrows }
start

Ethiopia
University

Bahir Dar
University

peda Poly yibab

end
Fikreselam G. Title: Introduction to LATEX October 28,2017 71 / 76
\tikzstyle {block} = [draw, rectangle, fill=green, text width=2cm, text
centered, rounded corners, minimum height=1cm]
\tikzstyle {cloud } = [draw, ellipse,fill=yellow, node distance=2cm,
minimum height=0.5cm]
\tikzstyle {line} = [draw, -latex’]
\begin {tikzpicture}[node distance = 2cm, auto]
\node [cloud] (s) {start};
\node [block, below of=s] (E) {Ethiopia University};
\node [block, below of=E] (B) {Bahir Dar University };
\node [block, below of=B] (p) {Poly};

Fikreselam G. Title: Introduction to LATEX October 28,2017 72 / 76


\node [block, left of=p, node distance=3cm] (pe) {peda};
\node [block, right of=p, node distance=3cm] (y) {yibab};
\node [cloud, below of=p, node distance=1.5cm] (e) {end};
\path [line] (s) – (E);
\path [line] (E) – (B);
\path [line] (B) – (p);
\path [line] (B) -— (pe);
\path [line] (B) -— (y);
\path [line] (p) – (e);
\path [line] (pe) – (e);
\path [line] (yi) – (e);
\end {tikzpicture}
Fikreselam G. Title: Introduction to LATEX October 28,2017 73 / 76
Page Numbering

LATEX do automatically number the pages using Arabic numbers.

using \thispagestyle {empty} you can omit page number at a


specific page.

\pagenumbering {arabic} for Arabic number and \pagenumbering


{roman} for Roman number

Fikreselam G. Title: Introduction to LATEX October 28,2017 74 / 76


Page Numbering

Use \addcontentsline { toc} {section} {...} to add Abstract,


Acknowledgement , L and Tables , references and any other to
TOC. This command directly create dot on toc.

To include dot for chapters use the following commands:


\usepackage {tocloft} \renewcommand { \cftchapleader } {
\cftdotfill { \cftdotsep} }

set line space using \usepackage { setspace } and \setstretch{}.

Fikreselam G. Title: Introduction to LATEX October 28,2017 75 / 76


Thank you

Fikreselam G. Title: Introduction to LATEX October 28,2017 76 / 76

You might also like