Latex Book
Latex Book
1 What is LaTeX?
LaTeX is a document preparing system for high-quality typesetting. It is used for Articles, Research
Papers, Scientific and Technical Documents, Presentations, Law-Texts, Scorecards, Bills, Letters,
Books, Reports and almost any form of publishing. LaTeX maintains its standards. A high quality
auto formatting of the content is perhaps the best feature in LaTeX. Just we have to take care of
the proper content and rest will be done by LaTeX.
2 Why LaTeX?
→ Open Source and Freeware
→ Available for Windows, Linux, Macintosh, Browsers, Android
→ Low Sized documents with High Quality Outputs
→ Post Script and Pdf Outputs
→ Extremely Stable: Handles very large and complex documents Smoothly
→ Cross Referencing Capabilities : Figures, Tables, Equations, Index etc.
→ Automatic Numbering: Chapters, Sections, Figures, Equations etc.
→ Automatic Generations : List of Contents, List of Figures, Index, Bibliography etc.
→ Constantly Evolving and Standard is maintained
→ Same Output Anytime, Anywhere on Any Operating System
4 Installing LaTeX
For creating and viewing documents, two things are required:
i) TeX Distribution ii) LaTeX Editor.
TeX viewers and LaTeX Editors are available across platforms: Windows, Linux, Mac OS, Browser-
based and Android. For Windows Operating System, following is the list of some of popular TeX
distributions and LaTeX editors. Many of LaTeX editors are freewares while some of them are
sharewares.
TeX Distributions LaTeX Editors
To begin creating your documents you may use “Miktex + Texworks Editor” or ”Miktex + “Texnic
Centre” or maybe “Miktex + Tex Studio”.
5 Understanding Basics
There are very few basic things that you need to understand . . . not more than two . . .
A) Command Format in LaTeX
\CommandName[Optional Argmument]{Compulsory Argument}
OR
\CommandName{Compulsory Argument}[Optional argument]
Every Command in LaTeX is of this form. It starts with Backslash followed by Command
Name, Optional Arguments in Square Brackets (if any) and Compulsory Arguments in Curly
Brackets.
Examples:
\documentclass[11pt]{article}
\documentclass{article}
\documentclass{article}[11pt]
B) Environments in LaTeX
\begin{environment}
...
...
\end{environment}
Believe it or not . . . if you clearly understood the above basics, half of the job is done. You
are advised to read the above basics once again.
Remember:
A) \CommandName[Optional Argmument]{Compulsory Argument}
6 First Document
Type as in the following box.
\documentclass[11pt]{article}
\begin{document}
This is Our First Document.
\end{document}
Key Point: A doubleslash \\ is used for New Line. The alternative is to use \newline.
Similarly, \newpage is used for New Page.
8 New Paragraph
A Blank Line is used for new paragraph.
I Sentence in I Paragraph.\\
I Sentence in I Paragraph.
II Sentence in New Line but in Same Paragraph.
II Sentence in New Line but in Same Paragraph.
I Sentence in I Paragraph.\\
I Sentence in I Paragraph.
II Sentence in New Line and in New Paragraph.
II Sentence in New Line and in New Paragraph.
Points to Understand
A) Multiple Spaces are equivalent to Single Space in LaTeX. For example,
How Are You?
and
How Are You ?
produce same viz. How Are You?
B) Multiple Blank Lines are equivalent to Single Blank Line in LaTeX. For Example,
This is First Sentence.
This is Second Sentence.
and
This is First Sentence.
Tips
1. For manually adding spaces, type backslash and space ( \ ). It acts as Spacebar in LaTeX.
2. For manually adding blank lines, type backslash two times (\\). It acts as Enter in
LaTeX.
9 Font Styles
Key Point: For typing out many of special symbols, we just have to type \ before it.
11 Different Fonts
12 Font Size
\begin{raggedright}
This is RaggedRight text. This is RaggedRight text.
\end{raggedright}
\begin{center}
This is Center Aligned Text. This is Center Aligned Text.
\end{center}
\begin{raggedleft}
This is RaggedLeft text. This is RaggedLeft text.
\end{raggedleft}
14 Adding Horizontal and Vertical Space
\documentclass{article}
A horizontal space of 10 points.
\begin{document}
A horizontal \hspace{10pt} space of 10 points.\\ A horizontal space of 2 cm.
A horizontal \hspace{2cm} space of 2 cm.\\
A first Paragraph.
A first Paragraph.
Key Point: Use \hspace and \vspace for adding horizontal and vertical space.
15 Page Layout
\documentclass{article}
\begin{document}
This is a sample document.
\end{document}
Different Document Classes in LaTeX: Article, Letter, Book, Report, Slides , Beamer etc.
Key Point: Use Geometry Package for Selecting Paper Size, Setting Margins, Orientation.
16 Drawing Line
\documentclass{article}
\begin{document}
\rule{\linewidth}{1pt}
\end{document}
\documentclass{article} \documentclass{article}
\usepackage{enumitem} \usepackage{enumitem}
\begin{document} \begin{document}
\textbf{Small Roman List with dot} \textbf{Capital Alphabetic List with bracket}
\begin{enumerate}[label=\roman*.] \begin{enumerate}[label=\Alph*)]
\item First Member \item First Member
\item Second Member \item Second Member
\item Third Member \item Third Member
\end{enumerate} \end{enumerate}
\end{document} \end{document}
Small Roman List with dot Capital Alphabetic List with bracket
i. First Member A) First Member
ii. Second Member B) Second Member
iii. Third Member C) Third Member
Capital Roman List with Bracket Starting Small Numbered List INSIDE PARAGRAPH : This
from 3 is a list inside paragraph. 1. First Member 2. Second Mem-
III. First Member ber 3. Third Member.
IV. Second Member
V. Third Member
\documentclass{article} \documentclass{article}
\usepackage{paralist} \begin{document}
\begin{document} \textbf{Nested List}
\textbf{Small Alphabetic List INSIDE \begin{itemize}
PARAGRAPH:} \item First Memeber of Main List
This is a list inside paragraph. \item Second Member of Main List
\begin{inparaenum}[a)] \item Third Member of Main List
\item First Member \begin{itemize}
\item Second Member \item First Member of Sublist of Third Member
\item Third Member. \item Second Member of Sublist of Third Member
\end{inparaenum} \end{itemize}
\end{document} \item Fourth and Last Member of Main List
\end{itemize}
\end{document}
Key Points:
1. Use package enumitem for bullets and numbering.
2. Use package paralist for bullets and numbering inside a paragraph.
18 Listing Theorems, Examples, Def initions etc.
\documentclass{article} \documentclass{article}
\usepackage{paralist} \begin{document}
\begin{document} \textbf{Simple Definition List.}
\textbf{Definition List Inside Paragraph:} \begin{description}
\begin{inparadesc} \item[First Definition:]A first definition.
\item[First Definition:]A first definition. \item[Second Definition:]A second definition.
\item[Second Definition:]A second \item[Third Definition:]A third definition.
definition. \end{description}
\item[Third Definition:]A third definition. \end{document}
\end{inparadesc}
\end{document}
Key Points:
1. To produce definition lists
\begin{description}...\end{description}
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\newtheorem{thmv}{Theorem}
\newtheorem{dfnb}{Definition}
\newtheorem{lem}{Lemma}
\begin{thmv}
Theorem 1 This is a theorem.
This is a theorem.
\end{thmv} Theorem 2 This is another theorem.
\begin{thmv} Definition 1 This is definition.
This is another theorem. Definition 2 This is another definition.
\end{thmv} Lemma 1 This is lemma.
\begin{dfnb}
This is definition.
\end{dfnb}
\begin{dfnb}
This is another definition.
\end{dfnb}
\begin{lem}
This is lemma.
\end{lem}
\end{document}
20 Tabs in LaTeX
\documentclass{article}
\begin{document}
\begin{tabbing}
\= Tab1 \= Tab2 \= Tab3 \= Tab4 \= Tab5 \= Tab6 \\ Tab1 Tab2 Tab3 Tab4 Tab5 Tab6
\> Tab1 \\ Tab1
\> \>Tab2 \\ Tab2
\> \> \> Tab3 \\
Tab3
\> \> \> \> Tab4 \\
\> \> \> \> \> Tab5 \\ Tab4
\> \> \> \> \> \> Tab6 Tab5
\end{tabbing} Tab6
\end{document}
Key Points:
1. Use \= to SET tab positions.
2. Use \> to MOVE to tab positions.
22 Tables
22.1 Simple Tables:
\documentclass{article}
\begin{document}
\textbf{Table: 3 columns (Center Aligned)}\\
Point to Understand:
2. l is used for left alignment, c is used for center alignment and r is used for right alignment.
3. & is used for separating entries in row.
4. \\ is used for end of row.
5. \hline is used for drawing horizontal line.
6. | is used for drawing vertical line.
\documentclass{article}
\begin{document}
\textbf{Table: 3 columns (Right Aligned)}\\
\documentclass{article}
\begin{document}
\textbf{Table: 3 columns (Left Aligned)}\\
\documentclass{article}
\begin{document}
\textbf{Table: 3 columns (Fixed Width)}\\
\documentclass{article}
\begin{document}
\textbf{Table: 3 columns (Right Aligned)}\\
\documentclass{article}
\begin{document}
\textbf{Table: 3 columns (Left Aligned)}\\
\documentclass{article}
\usepackage{array}
\begin{document} Cell Alignment:
\textbf{Cell Alignment:}\\
top
\begin{tabular}{|b{1.6cm}|m{1.6cm}|p{1.6cm}|} middle
aligned bottom
\hline aligned
aligned
top aligned & middle aligned & bottom aligned\\
\hline
\end{tabular}
\end{document}
\documentclass{article}
\usepackage{array}
\begin{document}
\setlength{\extrarowheight}{4pt} 11 12 13
\begin{tabular}{|c|c|c|}
\hline 21 22 23
11 & 12 & 13\\
\hline
21 & 22 & 23 \\
\hline
\end{tabular}
\end{document}
\documentclass{article}
\usepackage{array}
\begin{document}
\setlength{\extrarowheight}{16pt}
\begin{tabular}{|c|c|c|} 11 12 13
\hline
11 & 12 & 13\\
\hline 21 22 23
21 & 22 & 23 \\
\hline
\end{tabular}
\end{document}
\documentclass{article}
\usepackage{array}
\begin{document}
Column 1 Column 2 Column 3
\begin{tabular}{ccc} 11 12 13
\hline 21 22 23
\textbf{Column 1} & \textbf{Column 2} & \textbf{Column 3} \\
\hline
31 32 33
11 & 12 & 13 \\
\hline
21 & 22 & 23 \\
&\\
\hline
31 & 32 & 33 \\
\hline
\end{tabular}
\end{document}
\documentclass{article}
\usepackage{slashbox}
\begin{document}
\begin{tabular}{|c|c|c|}
\hline
\backslashbox{row}{column} & B & C \\
\hline
11 & 12 & 13 \\
\hline
21 & 22 & 23 \\
\hline
31 & 32 & 33 \\
\hline
\end{tabular}
\end{document}
Key Point: Use slashbox package for slashbox in a table.
\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{ccc} A B C
\toprule[1.5pt]
A & B & C \\ 11 12 13
\midrule 21 22 23
11 & 12 & 13 \\ 31 32 33
21 & 22 & 23 \\
31 & 32 & 33 \\
\bottomrule[1.5pt]
\end{tabular}
\end{document}
\documentclass{article}
\begin{document}
\begin{tabular}{ccc}
\hline Combined Column Last Column
\multicolumn{2}{l}{Combined Column}& 11 12 13
\multicolumn{1}{l}{Last Column}\\ 21 22 23
\hline 31 32 33
11 & 12 & 13 \\
21 & 22 & 23 \\
31 & 32 & 33 \\
\hline
\end{tabular}
\end{document}
Key Point: Use \multicolumn for merging cells in a row. The command format is
\multicolumn{cols}{pos}{text}
Point to Understand: \cline is used to draw horizontal line from first column to second
column after first row.
\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{ccc} Combined Column Last Column
\toprule[1.5pt] A B C
\multicolumn{2}{l}{Combined Column}&
\multicolumn{1}{l}{Last Column}\\ 11 12 13
A & B & C\\ 21 22 23
\cmidrule(r){1-2}\cmidrule(l){3-3} 31 32 33
11 & 12 & 13 \\
21 & 22 & 23 \\
31 & 32 & 33 \\
\bottomrule[1.5pt]
\end{tabular}
\end{document}
\documentclass{article}
\usepackage{multirow}
\begin{document}
\begin{tabular}{cccc} A 11 12
Combined Row
\hline B 21 22
\multirow{2}{*}{Combined Row} & A & 11 & 12\\ Last Row C 31 32
& B & 21 & 22 \\
\hline
\multirow{1}{*}{Last Row} & C & 31 & 32 \\
\hline
\end{tabular}
\end{document}
\documentclass{article}
\usepackage{booktabs}
\usepackage{multirow}
\begin{document}
\begin{tabular}{cccc} A 11 12
\toprule[1.5pt] Combined Row
B 21 22
\multirow{2}{*}{Combined Row} & A & 11 & 12\\
& B & 21 & 22 \\ Last Row C 31 32
\hline
\multirow{1}{*}{Last Row} & C & 31 & 32 \\
\bottomrule[1.5pt]
\end{tabular}
\end{document}
\documentclass{article}
\begin{document}
\begin{table}[htbp]
\begin{tabular}{ccc}
\hline Column 1 Column 2 Column 3
\textbf{Column 1} & \textbf{Column 2} & \textbf{Column 3} \\ 11 12 13
\hline 21 22 23
11 & 12 & 13 \\
31 32 33
\hline
21 & 22 & 23 \\
\hline Table 1: Table Name - Below
31 & 32 & 33 \\
\hline
\end{tabular}
\centering
\caption{Table Name - Below}
\end{table}
\end{document}
\documentclass{article}
\begin{document}
\begin{table}[htbp]
\centering
\caption{Table Name - Above}
\vspace{10pt} Table 1: Table Name - Above
\begin{tabular}{ccc}
\hline Column 1 Column 2 Column 3
\textbf{Column 1} & \textbf{Column 2} & \textbf{Column 3} \\ 11 12 13
\hline
21 22 23
11 & 12 & 13 \\
\hline 31 32 33
21 & 22 & 23 \\
\hline
31 & 32 & 33 \\
\hline
\end{tabular}\\
\end{table}
\end{document}
Key Point: Put tabular environment in table environment. Use \caption before or after
tabular environment.
11 12 13 11 12 13 11 12 13
21 22 23 21 22 23 21 22 23
31 32 33 31 32 33 31 32 33
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}[htbp]
\begin{center}
\includegraphics[width=0.3\textwidth, angle=0]{sample.jpg}
\caption{Sample Figure}
\end{center}
\end{figure}
Figure 1: Sample Figure
\end{document}
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}[htbp]
\begin{center}
\fbox{\includegraphics[width=3cm,
angle=0]{sample.jpg}}
\caption{Sample Figure} Figure 2: Sample Figure
\end{center}
\end{figure}
\end{document}
Points to Understand:
1. 0.3\width denotes 30% of total page width.
2. \fbox is used to frame the figure. It can also be used to frame the text.
24 Mathematics Environment in LaTeX
24.1 Understanding Basics
a) \( ... \) OR $ ... $
You are strongly advised to read the above basics at least once.
\documentclass{article}
\begin{document}
Equations are \( a + b = c \) and \( x + y Equations are a + b = c and x + y = z
= z \)
\end{document}
Equations are
\documentclass{article}
\begin{document} a+b=c
Equations are \[ a + b = c \] and \[ x + y = z \]
\end{document} and
x+y =z
\documentclass{article}
\begin{document}
Equation are Equation are
\begin{equation}
a + b = c a+b=c (1)
\end{equation}
\begin{equation} x+y =z (2)
a + b = c
\end{equation}
\end{document}
Tip: Use \begin{fleqn} ...\end{fleqn} for left aligned unnumbered equations.
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{multline}
x = a + b + c + d + e+ \\ x = a + b + c + d + e+
f + g + h + i + j+ \\
k + l + m + n f + g + h + i + j+
\end{multline} k + l + m + n (3)
\begin{gather}
x + y + z = 0\\ x+y+z =0 (4)
y + z = 1 y+z =1 (5)
\end{gather}
\begin{equation}
\begin{split} a=b
a = b\\ (9)
=c
=c\\
\end{split}
\end{equation}
\end{document}
Points to Understand:
1. Alignment of Equations is done with amsmath package.
2. Multiline is used for equations longer than a line.
3. Gather is used to centre align list of equations.
4. Align is used to vertically align the equations w.r.t. <, >, = etc.
5. Split is used to align right hand sides of equations w.r.t. <, >, = etc.
24.8 Accents
\documentclass{article}
\begin{document}
\[\bar{a},\vec{a},\hat{a}\] ā, ~a, â
z}|{
\[\overbrace{abc},\underbrace{abc}\] abc , |{z}
abc
\end{document}
24.11 Summations
\documentclass{article}
\begin{document} P
\[\sum\]
P
\[\sum a + b + c + \ldots\] a + b + c + ...
Pn=∞ 1
\(\sum_{n=1}^{n=\infty}\frac{1}{n}\) n=1 n
n=∞
\(\sum\limits_{n=1}^{n=\infty}\frac{1}{n}\)
P 1
n
n=1
\end{document}
n!
\[^nC_r = \frac{n!}{r!(n-r)}\] nCr = r!(n−r)
nP n!
\[^nP_r = \frac{n!}{(n-r)!} \] r = (n−r)!
\end{document}
24.13 Limits
\documentclass{article}
\begin{document}
1
\(\lim_{n \to \infty}\frac{1}{n} = 0\) limn→∞ n =0
n
\(\lim_{n \to \infty}{(1 + \frac{1}{n})}^{n} = e\) limn→∞ (1 + n1 ) = e
n
\(\lim\limits_{n \to \infty}{(1 + \frac{1}{n})}^{n} = e\) lim (1 + n1 ) = e
n→∞
\end{document}
24.14 Derivatives
\documentclass{article}
\begin{document}
dy
\[\frac{dy}{dx}\] dx
d2 y
\[\frac{d^2y}{dx^2}\] dx2
\end{document}
24.15 Integration
\documentclass{article}
\begin{document} R H
\(\int,\oint\) ,
R R
\(\int f(x)\,dx, \int \!f(x)\,dx\) f (x) dx, f (x) dx
R 2π R 2π
\(\int_{0}^{2\pi}x\,dx, \int_{0}^{2\pi}\!x\,dx \) 0 x dx, 0 x dx
R2π R2π
\(\int\limits_{0}^{2\pi}x\,dx, \int\limits_{0}^{2\pi}\!x\,dx\) x dx, x dx
0 0
R 2π R 2π
\(\int_{0}^{2\pi}x\,\mathrm{d}x, \int_{0}^{2\pi}\!x\,\mathrm{d}x\) 0 x dx, 0 x dx
R2π R2π
\(\int\limits_{0}^{2\pi}x\,\mathrm{d}x, \int\limits_{0}^{2\pi}\!x\,\mathrm{d}x\) x dx, x dx
0 0
\end{document}
Points to Understand:
R
1. \! is used to reduce space between and integrand.
2. \limits is used for proper placing of limits in inline equations.
3. \mathrm is used for proper formatting of differential d.
24.16 Double Integration
\documentclass{article}
\usepackage{amsmath}
\begin{document} RR RR
\(\iint, \iint f(x)\,dx\) , f (x) dx
RR
\(\iint f(x)\,dx\,dy\) f (x) dx dy
RR
\(\iint_D f(x)\,dx\,dy \) D f (x) dx dy
RR
\(\iint\limits_D f(x)\,dx\,dy \) f (x) dx dy
D
RbRd
\(\int_{a}^{b}\int_{c}^{d} f(x)\,dx\,dy\) a c f (x) dx dy
Rb Rd
\(\int\limits_{a}^{b}\int\limits_{c}^{d} f(x)\,dx\,dy\) f (x) dx dy
a c
RR
\(\iint \!f(x)\,dx\,dy\) f (x) dx dy
RR
D f (x) dx dy
\(\iint_D \!f(x)\,dx\,dy \)
RR
\(\iint\limits_D \!f(x)\,dx\,dy \) f (x) dx dy
D
RbRd
\(\int_{a}^{b}\int_{c}^{d}\!f(x)\,dx\,dy\) a c f (x) dx dy
Rb Rd
\(\int\limits_{a}^{b}\int\limits_{c}^{d} \!f(x)\,dx\,dy\) f (x) dx dy
a c
RR
D f (x) dx dy
\(\iint_D \!f(x)\,\mathrm{d}x\,\mathrm{d}y \)
RR
\(\iint\limits_D \!f(x)\,\mathrm{d}x\,\mathrm{d}y \) f (x) dx dy
D
RbRd
\(\int_{a}^{b}\int_{c}^{d}\!f(x)\,\mathrm{d}x\,\mathrm{d}y\) a c f (x) dx dy
Rb Rd
\(\int\limits_{a}^{b}\int\limits_{c}^{d} \!f(x)\,\mathrm{d}x\,\mathrm{d}y\) f (x) dx dy
a c
\end{document}
a11 a12 a a a11 a12 a11 a12
A = 11 12 A=
a21 a22
A=
a21 a22
a21 a22 a21 a22
a a a11 a12 a a a11 a12
A = 11 12 A= A = 11 12 A=
a21 a22 a21 a22 a21 a22 a21 a22
\documentclass{article} \documentclass{article}
\usepackage{amsmath} \usepackage{amsmath}
\begin{document} \begin{document}
\[ A = \begin{vmatrix} \[ A = \begin{Vmatrix}
a_{11} & a_{12}\\ a_{11} & a_{12}\\
a_{21} & a_{22} a_{21} & a_{22}
\end{vmatrix} \] \end{Vmatrix} \]
\end{document} \end{document}