Sie sind auf Seite 1von 42

LaTex: An Effective

Tool for Researchers


1
Part I
A very quick look at typesetting documents

Dr. Syed Zulqadar Hassan


FAST National University of Computer
2

Introduction to LaTeX
3

Introduction
 Essentially a Markup Language (like HTML, XML and
RTF)
 An extension to TeX system
 TeX written by Donald Knuth in 70´s
4

Installation on Different OS
5 Installing LaTeX

 In Windows
 MiKTeX
 MiKTeX is a typesetting system for the Windows.
 Download from www.miktex.org for free
 It is generally recommended to install MiKTeX first,
then Tex.
 Other text editors
 There are other text editors.
 TeXstudio http://www.texstudio.org/
6 Installing LaTeX

In Mac or Unix


Download from
http://www.tug.org/mactex/
7

Why LaTeX is Preferred on


MS-Word
8 Latex vs. Word Processors

 High typeset quality


 Easy to include math formulas
 Source file format id not bounded to a particular OS or
platform
 Latex implementations exists for all platforms (DOS,
Windows, Unices,..)
 Latex is free
 Very few bugs
 Good for large documents
 Can run even on 386 PC
 Not very easy to learn
9

Basic Commands of LaTeX


10

Latex File Structure


 Document Class
Predefined Formats (article, report, book,..).

 Packages used
Added Functionality (graphics, reference style,...).

 Main Body
Text and Bibliography References.
11

The Basics
 Document Class
\documentclass[options]{class}
options = a4paper, 11pt, 12pt, 10pt,
twocolumn, landscape,...
class = article, report, book,...
 Packages
\usepackage{package name}
epsfig = insert PS pictures into the
document
fancyhdr = easy definition of footer
and header
12
Body of Text
 Start with \begin{document}
 End with \end{document}
 Typesetting Text
 \\ or \newline and \newpage
 Quotations
 Bold \textbf{……………} or \bf
 Italics \emph{…………} or \textit{………} or
\it
 Underline \underline{…………} or \ul
 Including Multiple Files
 \input{filename.tex}
13 Format

 Sections
 \section{…} = 1. Latex is Great
 \subsection{…} = 1.1 Why Latex is Great
 \subsubsection{…} = 1.1.1 Reason One
 \appendix - changes numbering scheme
 \chapter{…} - To be used with book and
report document classes
 Titles, Authors and others
 \title{…} \author{…}
 \footnote{…}
14
Format Contd.
 \maketitle - Display Title and Author
 \tableofcontents - generates TOC
 \listoftables - generates LOT
 \listoffigures - generates LOF
 Itemise
 Use either enumerate, itemize or description.
 see handout for example.
15
Format Contd.
\documentclass{article}
\begin{document}
\tableofcontents
\newpage
\section{Section}
Dummy text
\subsection{Subsection}
Dummy text
\end{document}
16
Format Contd.
\begin{document} ...
... \begin{appendix}
\begin{figure}
\listoffigures
\caption{Dummy figure}
\listoftables
\end{figure}
\end{appendix}
\end{document}
\begin{table}
\caption{Dummy table}
\end{table}
17 Lists
 Source
 \begin{itemize}
 \item Apple
 \item Orange
 \end{itemize}
 Result
 Apple
 Orange
18 Lists
 Source
 \begin{enumerate}
 \item One
 \item Two
 \item Three
 \end{enumerate}
 Result
1. One
2. Two
3. Three
19 Lists
\documentclass{article}
% ...
\usepackage{enumitem}
\begin{document}
---------------

%Roman numbers
\begin{enumerate}[label=(\roman*)]
%...

% Arabic numbers
\begin{enumerate}[label=\arabic*)]
%...

% Alphabetical
\begin{enumerate}[label=\alph*)]
%...
20 Environment

 Something between
 \begin{name}
 \end{name}

 Can be recursive
 Examples:
 itemize, center, abstract
21 Group

 Text between { and }


 Many commands work until the end of the group
 Code
 put {one word \bf in bold} here
 Result
 put one word in bold here
22 Alignment

 Environments center, flushleft, flushright


 Example
 \begin{flushright}
 Right aligned
 \end{flushright}

 Result
Right aligned
23 Font size

\tiny \scriptsize \footnotesize

\small \normalsize

\large \Large
\LARGE \huge
\Huge
24 Footnote
I'm writing something here to test \footnote{footnotes working fine}
several features.
25
Images

Use graphicx package


 \usepackage{graphicx}
Including images in main body
 \\includegraphics
{file=filename.jpg, width=10cm,
height=9cm}
26

Tables and Figures


27 Images
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\includegraphics[width=\linewidth]{boat.png}
\caption{A boat.}
\label{fig:boat1}
\end{figure}
Figure \ref{fig:boat1}
shows a boat.
\end{document}
28 Images
\begin{figure}[h!]

 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
29 Images
\documentclass{article} \end{subfigure}

\usepackage{graphicx} \begin{subfigure}[b]{0.4\linewidth}
\usepackage{subcaption}
\includegraphics[width=\linewidth]
\begin{document} {coffee.jpg}
\caption{More coffee.}
\begin{figure}[h!]
\end{subfigure}
\centering \caption{The same cup of coffee.
Two times.}
\begin{subfigure}[b]{0.4\linewidth} \label{fig:coffee}
\end{figure}

\includegraphics[width=\linewidth \end{document}
]{coffee.jpg}
\caption{Coffee.}
30 Images
31
Tabular

 Columns Two Columns


\begin{tabular}{|…|…|} l = automatically adjust
size, left justify
\end{tabular} r = automatically adjust
size, right justify
 Rows p = set size
& - Split text into columns e.g p{4.7cm}
c = centre text
\\ - End a row
\hline - Draw line under row
e.g. 123123 & 34.00\\ \hline
32 Example of table
\documentclass{article}
\begin{document}
\begin{table}[h!]
\begin{center}
\caption{Your first table.}
\label{tab:table1}
\begin{tabular}{l|c|r}
\textbf{Value 1} & \textbf{Value 2} & \textbf{Value 3}\\
$\alpha$ & $\beta$ & $\gamma$ \\
\hline
1 & 1110.1 & a\\
2 & 10.1 & b\\
3 & 23.113231 & c\\
\end{tabular}
\end{center}
\end{table}
\end{document}
33 Example of table (Multiple Row)
\usepackage{multirow} % Required for multirows
\begin{document}
\begin{table}[h!]
\begin{center}
\caption{Multirow table.}
\label{tab:table1}
\begin{tabular}{l|S|r}
\textbf{Value 1} & \textbf{Value 2} & \textbf{Value 3}\\
$\alpha$ & $\beta$ & $\gamma$ \\ \hline
\multirow{2}{*}{12} & 1110.1 & a\\ & 10.1 & b\\ % <--
Content of first column omitted.
\hline
3 & 23.113231 & c\\
4 & 25.113231 & d\\
\end{tabular}
\end{center}
\end{table}
34

Mathematical Equations,
Algorithms
35 Mathematical expressions

In physics, the mass-energy equivalence is stated


by the equation $E=mc^2$, discovered in 1905 by Albert
Einstein.
36 Mathematical expressions
The mass-energy equivalence is described by the famous
equation

$E=mc^2$

discovered in 1905 by Albert Einstein.


In natural units ($c$ = 1), the formula expresses the identity

\begin{equation}
E=m
\end{equation}
37 Mathematical expressions
\documentclass{article}

\usepackage{amsmath}

\begin{document}

\begin{align*}
f(x) &= x^2\\
g(x) &= \frac{1}{x}\\
F(x) &= \int^a_b \frac{1}{3}x^3
\end{align*}

\end{document}
38 Alogrithms
\usepackage[options ]{algorithm2e}
Example
------------
\begin{algorithm}[H]
\SetAlgoLined
\KwResult{Write here the result }
initialization\;
\While{While condition}{
instructions\;
\eIf{condition}{
instructions1\;
instructions2\;
}{
instructions3\;
}
}
\caption{How to write algorithms}
\end{algorithm}
39

Labels and Cross-references


40 Labels and Cross-references
Labels
• \label{marker} - Marker in document.
• \pageref{marker} - Displays page no. of marker.
• \ref{marker} - Displays section location of marker.

\section{Greetings}
\label{sec:greetings}

Hello!

\section{Referencing}

I greeted in
section~\ref{sec:greetings}.
41 Labels and Cross-references
\begin{figure}
\centering

\includegraphics[width=0.5\textwidth]
{gull}
\caption{Close-up of a gull}
\label{fig:gull}
\end{figure}
Figure \ref{fig:gull} shows a
photograph of a gull.
42 Labels and Cross-references
\begin{equation} \label{eq:solve}
x^2 - 5 x + 6 = 0
\end{equation}
\begin{equation}
x_1 = \frac{5 + \sqrt{25 - 4 \times 6}}{2} = 3
\end{equation}
\begin{equation}
x_2 = \frac{5 - \sqrt{25 - 4 \times 6}}{2} = 2
\end{equation}
and so we have solved equation~\ref{eq:solve}

Das könnte Ihnen auch gefallen