How to specify size of image in LaTeX

An image is inserted into a LaTeX document using the includegraphics command. The size of the image can be specified in a variety of techniques:

  • Specify height or width or both in terms of cm:
width=5cm

height=3cm

width=3cm, height=10cm
  • Specify width as fraction of width of text column:
width=0.9\linewidth

width=0.7\textwidth
  • Specify scale of image:
scale=0.5

Tried with: Ubuntu 14.04

How to add subfigures using subfigure package

Multiple figures are sometimes arranged together in a single figure in a paper or book written in LaTeX. This can be done using subfig and subfloat packages. I recently discovered the subfigure package which can be used to achieve the same with less code!

Below is LaTeX code to arrange three subfigures in two rows, one figure in top row and two figures in bottom row:


% Arrange three figures like this:
% Fig 1
% Fig 2 Fig 3
\begin{figure}
\centering
\subfigure[]
{
\includegraphics[scale=.2]{foo1.pdf}
}
\\
\subfigure[]
{
\includegraphics[scale=.5]{foo2.pdf}
}
\qquad
\subfigure[]
{
\includegraphics[scale=.26]{foo3.pdf}
}
\caption
{
(a) blah
(b) blah
(c) blah
}
\label{fig:foobar}
\end{figure}

Tried with: Ubuntu 14.04

Inserting a figure in LaTeX

Inserting a figure or any image in LaTeX requires the graphicx package. The figure can be given a caption and a label. The label can be used to refer to the figure anywhere in the document and LaTeX will replace that reference with the figure number when it creates the output document.


% At the beginning of the document
\usepackage{graphicx}
% At the place you want a figure
\begin{figure}[h]
\centering
\includegraphics[scale=0.3]{pics/foobar.png}
\caption{This is a caption for the figure.}
\label{foobar-figure}
\end{figure}
% Refer to the figure when you want to
As shown in Figure \ref{foobar-figure}, the Foobar is a good choice.

Tried with: MikTeX 2.9 on Windows 7 64-bit

How to divide frame into columns in Beamer

In a Beamer frame, you might need to present 2 or more figures or a figure and textual content beside each other. The columns environment of Beamer can be used to achieve this by subdividing the frame into columns.

To do this enclose all the frame content within a columns environment:

\begin{frame}{Fixing an Optical Mouse}
\begin{columns}
% Frame content here
\end{columns}
\end{frame}

To create a column of content inside this environment of say, 0.6 width of the total frame width use:

\column{0.6\textwidth}
% Content of this column here

The content of this column follows after this. Do this for each column you want. The widths of all the columns should add up to 1.0.

The frame shown above has 2 columns, of width 0.6 and 0.4 respectively, holding a figure and some text. It was generated from this snippet of LaTeX code:

\begin{frame}{Fixing an Optical Mouse}
\begin{columns}
	\column{0.6\textwidth}
	\includegraphics[scale=0.3]{mouse.png}

	\column{0.4\textwidth}
	\begin{itemize}
	\item{Open mouse.}
	\item{Fix internals of mouse.}
	\item{Close mouse.}
	\end{itemize}
\end{columns}
\end{frame}