Figures

Code snippets for figures:

 

Standard figure
%Preamble
\usepackage{graphicx}

%Document
\begin{figure}[htbp]
\centering
\includegraphics[width=\linewidth]{figure.png}
\caption[short for lof]{long figure caption}
\label{fig:default}
\end{figure}
\ref{fig:default}

 

Side-by-side figure (1×2)
%Preamble
\usepackage[lofdepth]{subfig}
\usepackage{graphicx}

%Document
\begin{figure}[htbp] % h:here; t:top; b:bottom; p:page; default:ht
\centering
 \subfloat[short for lof][long subfigure1 caption]{
   \includegraphics[width=0.45\linewidth]{figure1.png}
   \label{subfig:fig1}
 }
 \subfloat[short for lof][long subfigure2 caption]{
   \includegraphics[width=0.45\linewidth]{figure2.png}
   \label{subfig:fig2}
}
\caption[short for lof]{long figure caption}
\label{fig:fig1}
\end{figure}
\ref{fig:fig1} and \subref{subfig:fig1}

 

Side-by-side figure (2×2)
%Preamble
\usepackage[lofdepth,lotdepth]{subfig}
\usepackage{graphicx}

%Document
\begin{figure}[ht]
\centering
 \subfloat[short for lof][long subfig1 caption]{
   \includegraphics[width=0.45\linewidth]{figure1.png}
   \label{subfig:fig1}
 }
 \subfloat[short for lof][long subfig2 caption]{
   \includegraphics[width=0.45\linewidth]{figure2.png}
   \label{subfig:fig2}
}

 \subfloat[short for lof][long subfig3 caption]{
   \includegraphics[width=0.45\linewidth]{figure3.png}
   \label{subfig:fig3}
 }
 \subfloat[short for lof][long subfig4 caption]{
   \includegraphics[width=0.45\linewidth]{figure4.png}
   \label{subfig:fig4}
}
\caption[short for lof]{long figure caption}
\label{fig:fig1}
\end{figure}
\ref{fig:fig1} and \subref{subfig:fig1}

 

Sideways-figure
% Preamble
\usepackage{rotating}

% Document
\begin{sidewaysfigure}
\centering
\includegraphics{figure.png}
\caption{Sideways figure.}
\label{fig:swfig}
\end{sidewaysfigure}

 

Wrap text around figure
%Preamble
\usepackage{wrapfig, graphicx}

% Document
\begin{wrapfigure}{l}{0.5\textwidth} % l for left, r for right
\centering
\includegraphics[width=0.45\textwidth]{test}
\caption{Text wrapped around figure}
\label{fig:wrapfig}
\end{wrapfigure}

6 Comments

  1. giannis

  2. giannis

    Hey Tom once again,
    How could I draw a hyperbola with the tikz package?
    For example, I would like, how could I have the hyperbola: y=2000/(x+16.67).
    Thanks in advance.

  3. fk

    hi,
    your 1×2 code produces subfigures with two brackets like ((a)) but it would be nicer to have (a)

    thanks for nice code snippets :)

    • Hi!

      Thanks for your comment. I don’t get double parentheses using the standard LaTeX classes. What document-class do you use?

      You can try to set the label format manually, through the caption package (page 6):

      \usepackage{caption}
      \captionsetup[subfigure]{labelformat=parens, labelsep=none}

Leave a Reply