Showing posts with label Figures in LaTex. Show all posts
Showing posts with label Figures in LaTex. Show all posts

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