Tuesday, October 1, 2019

Figures in LaTex

Figures

In LaTex we have figure commands to use a figure.  We can add PDF, PNG, JPEG\or GIF files.

\begin{figure}
......
\end{figure}

Ex. 
\documentclass[options]{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}[h]
\centering
\includegraphics[width=0.5\textwidth]{img.jpg}
\caption{Here is my image}
\label{image-myimage}
\end{figure}
\end{document}

[width=1\textwidth]  specifies the width of the picture 

For alignment from left or right we need to add
\usepackage[export]{adjustbox}

Ex.
\includegraphics[width=0.5\textwidth, right]{img}

Multiple images in one figure

use package{subcaption} and the environment \subfigure 

Ex.
\documentclass[options]{article}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\usepackage{subcaption}
\begin{document}
\begin{figure}[h]
\begin{subfigure}{0.5\textwidth}
\includegraphics[width=0.9\linewidth, height=5cm]{Table1} 
\caption{Caption1}
\label{fig11}
\end{subfigure}
\begin{subfigure}{0.5\textwidth}
\includegraphics[width=0.9\linewidth, height=5cm]{Table2}
\caption{Caption 2}
\label{fig12}
\end{subfigure}
\caption{Caption for this figure with two images}
\label{fig2}
\end{figure}
\end{document}

Wrapping text around a figure

import package wrapfig shown below

Ex.

\documentclass[options]{article}
\usepackage{graphicx}
\usepackage{wrapfig}
\begin{document}
\begin{wrapfigure}{l}{0.25\textwidth}
\includegraphics[width=0.9\linewidth]{Table1} 
\caption{Caption1}
\label{fig1}
\end{wrapfigure}
\end{document}

Note:

\textwidth is the width of the total text block

\columnwidth is the width of a single column of text

\linewidth means the current size of the line of text

\graphicspath{ {./img/} } if you want to put images in a folder named img under the directory of the tex document


use absolute path if the location is different

\graphicspath{ {c:/user/img/} } this command should be written in preamble


for Linux, Mac OS

\graphicspath{ {/home/user/img/} }


for multiple folders

\graphicspath{ {./img1/}{./img2/} }


for scaling

\includegraphics[scale=2]{img-name}

for definining specific width and the height of the image

\includegraphics[width=3cm, height=4cm]{lion-logo}


For rotation

\includegraphics[scale=1.2, angle=45]{lion-logo}


Positioning parameters 

\begin{figure}[t]

h: Places approximately at the same point it occurs in the source 

t: Places at the top of the page

b: Places at the bottom of the page

p: Put on a special page for floats only.

!: Override internal parameters LaTeX determines best positions




Table in LaTeX

Table

In LaTeX we use tabular command to typeset a table. 

\begin{tabular}{...}
......

\end{tabular}

The codes for columns are defined as follows
l left-alignment
r right-alignment
c centre-alignment
| for vertical line
& is used to separate columns
\\  for end of a row
\newline for a new line within a cell 
\hline for a horizontal line.
\cline{i-j} inserts a partial horizontal line between column i and j

Ex. {ll} (i.e. left left ) is used to create 2 columns with left-alignment text without vertical lines , whereas {|l|r|} (i.e. left right )  for 2 columns. The first column is left aligned and second column is right aligned  with vertical lines.

Tabular Code and output 

Ex. 1.
Output Ex. 1

\documentclass[options]{Article}
\begin{document}
\begin{tabular}{|l|r|}
RAM & ROM \\
Printer & Plotter \\
Keyboard & Mouse \\
\end{tabular}
\end{document}


Ex. 2.


Output Ex. 2
\documentclass[options]{Article}
\begin{tabular}{|r|l|}
\hline
One & Two \\
\cline{2-2}
Three & Four \\
\hline \hline
Hello123 & Done \\
\hline
\end{tabular}
\end{document}


Output Ex. 3
Ex. 3.
\documentclass[options]{Article}
\begin{document}
\begin{tabular}{|r|r|r|r|}
\hline
Item & 2012 & 2013 & 2014 \\
\hline
Desktop & 23 & 25 & 26 \\
\hline
Laptop & 53 & 55 & 86 \\
\hline
Monitor & 13 & 85 & 28 \\
\hline
\end{tabular}
\end{document}

Ex. 4.
Output Ex. 4
\documentclass[options]{Article}
\usepackage{multirow}
\begin{document}
\begin{tabular}{l|rrr}
\multicolumn{4}{c}{Table 4}\\
\hline
\multirow{2}{4em}{Item} & \multicolumn{3}{c}{Year} \\
\cline {2-4}
 & 2012 & 2013 & 2014 \\
\hline
Desktop & 23 & 25 & 26 \\
\hline
Laptop & 53 & 55 & 86 \\
\hline
Monitor & 13 & 85 & 28 \\
\end{tabular}

\end{document}

Saturday, September 28, 2019

LaTeX Basics

LaTeX Tutorial 

Important Points

  • LATEX (pronounced as lay-tek ) is a document preparation system for producing high quality documents
  • It is different from Microsoft Word, LibreOffice Writer and Apple Pages
  • Microsoft Word, LibreOffice Writer and Apple Pages are  "What You See Is What You Get" (WYSIWYG) application
  • LaTeX was written in the early 1980s by Leslie Lamport
  • LATEX uses Tex Typesetting program developed by Donald Knuth in 1978
  • TeX and LATEX both are free 
  • Markup languages are used for processing, definition and presentation of text
  • A sequence of characters is inserted in a text processing file to specify how the file be supposed to look when it is printed.
  • A markup describes the document's logical structure.
  • The markup indicators are called "tags"
  • TeX commands start with a backslash and are grouped in curly braces
  • Latex is an extension of TeX
  • Latex is available for every platforms such as DOS, Windows, Unix, Linux etc.

Latex vs. Word Processors

  • Latex is used for scientific publishing
  • Typeset quality is high
  • Very few bugs
  • Very Good for large documents  
  • Can run smoothly on 386 PC
  • Difficult to learn

Latex File Structure

1. Document Class



Document Class: \documentclass command is the start of every LATEX document.

It ha redefined formats for article, report, book etc.

\documentclass[options]{class}

options = a4paper, 11pt, 12pt, 10pt, twocolumn, landscape etc.

class = article, report, book etc.

Ex.  \documentclass[]{article} 
\documentclass[a4paper,latin]{book}

2. Package inclusion:

For additional Functionality such as citation, graphics, reference style etc.
\usepackage{package name}
Ex.
\usepackage{color}
\usepackage{cite}

3. Main Body

For Text and Bibliography References.
\begin{document}
\end{document}
The \begin{document} and \end{document} commands is used to make up a LATEX document. Whatever typed before \begin {document} is identified as the preamble that change the whole document and after \end{document} everything is ignored by the system.

A simple Article Latex Code

 \documentclass[]{article}
\usepackage{color}
\usepackage{inputenc}

\usepackage{mathtools}

\title{Detection of DDOS Attack using Naive Bayes Classifier}
\author{\bf Md. Amir Khusru Akhtar}

\begin{document}

\maketitle

\begin{abstract}

Naive Bayes classifiers are a set of categorization techniques based on Bayes’ Theorem. .....
\end{abstract}
\it Keywords: Naïve Bayes Classifier, Denial-of-Service Attack, Bayes’ Theorem, Ddos, Dataset
\section{Introduction}

A denial-of-service attack is an attempt that makes a computer resource unavailable to the intended users by flooding of ....


\section{Mathematical Classifier Mode}

The proposed model uses a classifier function f that maps input feature vectors x $\in$ X to resultant class $y \in \{L1, L2,…, Ln\}$,......

\section{Numerical Simulation}


We have collected some IP packets from Scoreboard Dataset.....

\end{document}


OUTPUT


Note: for a blank date use \date{}

Basics of LATEX

Typesetting Text

Newline and New page 

NewLine: \\ or \newline 
Newpage: \newpage

Font Effects

Bold:  \textbf{……………} or \bf 
Italics: \emph{…………} or \textit{………} or \it
Underline: \underline{…………} or \ul

Color

for color write \usepackage{color}  before \begin{document}

\color{colour_name}

Ex.
\color{blue}

Font size

LATEX has a range of font sizes
\tiny 
\scriptsize  
\footnotesize 
\small  
\normalsize  
\large 
\Large 
\LARGE 
\huge

Ex.
\huge .....

Creating a Title 

The \maketitle command used to create a title. It is placed after the \begin{document}.
\title{}
\author{}
\date{}
\maketitle

Ex.
\title{DDoS Attack...}
\author{Dr. Md. Amir Khusru Akhtar}
\date{\today}
\maketitle

Sections

We can divide a document into chapters, sections and subsections. 
Commands of subsectioning article class:
\section{...}
\subsection{...}
\subsubsection{...}
\paragraph{...}
\subparagraph{...}

Ex.
\section{Mathematical Classifier Mode}
The proposed model uses a classifier function f that maps input feature vectors x $\in$ X to resultant class $y \in \{L1, L2,…, Ln\}$,......

\subsection{Simulation}


LIST

LATEX has two types of lists
1.      enumerate for  numbered lists
2.      itemize is for bulleted lists.

both list item can be defined by \item command and can be nested to produce sub lists.

Ex. enumerate

\begin{enumerate}
\item One
\item Two
\begin{enumerate}
\item Two one
\item Two two
\end{enumerate}
\item Three
\end{enumerate}

Ex. itemize

\begin{itemize}
\item One
\item Two
\begin{itemize}
\item Two one
\item Two two
\end{itemize} \item Three
\end{itemize}

OUTPUT

Example:

\documentclass{article}
\usepackage{enumerate}
\begin{document}
Enumerated List
\begin{enumerate}
\item one
\item two
\begin {enumerate} [{2.}1]
\item two one
\item two two
\end{enumerate}
\item three
\end{enumerate}
\end{document}

OUTPUT

Example
\documentclass{article}
\usepackage{amssymb}
\begin{document}
\renewcommand{\labelitemi}{$\blacksquare$}
\renewcommand\labelitemii{$\square$}
Itemize List
\begin{itemize}
\item one
\item two
\begin{itemize}
\item two one
\item two two
\end{itemize}
\item three
\end{itemize}
\end{document}

OUTPUT


Comments

Comments are defined using % character. When LATEX finds a % it ignores rest of the line.
Ex.
The proposed model uses a classifier function %Function definition
f that maps input feature vectors x $\in$ X to

OUTPUT