LaTeX Figures
Figures are the basic environment for inserting tabular or graphical content.
Contents
Usage
To insert a graphic, try using a figure together with the graphicx package:
\begin{figure}[h] \includegraphics{foo} \end{figure}
Figures take a mandatory positioning option, like h in the example above. Valid values and their meanings are:
Option |
Effect |
h |
Insert here |
H |
Insert here, exactly |
t |
Insert at page top |
b |
Insert at page bottom |
p |
Insert into a separate page for floating figures |
! |
Override LaTeX placement algorithm |
To center a figure, use the \centering command.
Captions
Captions are added using the \caption command.
\begin{figure}[h] \centering \caption{Hello, world!} \includegraphics{foo} \end{figure}
Subfigures
For advanced options such as side-by-side positioning, some number of subfigures must be created within an overarching figure.
\usepackage{graphicx} \usepackage{subcaption} % ... \begin{figure} \centering \begin{subfigure}{.5\textwidth} \centering \includegraphics{foo} \end{subfigure} ~ % inserted for spacing: any of `~`, `\quad`, `\qquad`, `\hfill`, etc will work \begin{subfigure}{.5\textwidth} \centering \includegraphics{bar} \end{subfigure} \end{figure}
Labels
To create references within a document, as in:
See figure~\ref{fig:test} on page~\pageref{fig:test}.
Use the \label command within figures. Figures should always use labels like fig:name.
Note that the \label command must follow the \caption command (if used), and must be encapsulated in the figure (rather than follow it).