# Looking for three images on top of each other with text underneath each

I need to place three images on a page with text under each, and then one 'overall' caption for the figure. This code puts the images on top of each other but the text is to the left of the images, I need the text under each image. E.g. n = 10 steps should be the text directly under the first image.

\begin{figure}[ht]
\centering
\subfigure[$n = 10$ steps]{
{\includegraphics[width=0.45\textwidth]{Raster/cw_10.png}
\label{cw_10}
}\\
\subfigure[$n = 25$ steps]{
{\includegraphics[width=0.45\textwidth]{Raster/cw_25.png}
\label{cw_25}
}\\
\subfigure[$n = 50$ steps]{
{\includegraphics[width=0.45\textwidth]{Raster/cw_50.png}
\label{cw_50}
}
\caption{Classical Random Walk with various step sizes.}
\label{TS}
\end{figure}

-

subfigure is an obsolete package which shouldn't be used anymore. You can use subfig or subcaption instead. Below, an example using \subcaptionbox from subcaption:

\documentclass{article}
\usepackage{subcaption}
\usepackage[demo]{graphicx}

\begin{document}

\begin{figure}
\centering
\subcaptionbox{$n = 10$ steps\label{cw_10}}{%
\includegraphics[width=0.45\textwidth]{Raster/cw_10.png}%
}\par\medskip
\subcaptionbox{$n = 25$ steps\label{cw_25}}{%
\includegraphics[width=0.45\textwidth]{Raster/cw_25.png}%
}\par\medskip
\subcaptionbox{$n = 50$ steps\label{cw_50}}{%
\includegraphics[width=0.45\textwidth]{Raster/cw_50.png}%
}
\caption{Classical Random Walk with various step sizes.}
\label{TS}
\end{figure}

\end{document}


And with subfig:

\documentclass{article}
\usepackage{subfig}
\usepackage[demo]{graphicx}

\begin{document}

\begin{figure}
\centering
\subfloat[$n = 10$ steps\label{cw_10}]{%
\includegraphics[width=0.45\textwidth]{Raster/cw_10.png}%
}\par
\subfloat[$n = 25$ steps\label{cw_25}]{%
\includegraphics[width=0.45\textwidth]{Raster/cw_25.png}%
}\par
\subfloat[$n = 50$ steps\label{cw_50}]{%
\includegraphics[width=0.45\textwidth]{Raster/cw_50.png}%
}
\caption{Classical Random Walk with various step sizes.}
\label{TS}
\end{figure}

\end{document}


The demo option for graphicx simply replaces actual figures with black rectangles; do not use that option in your actual document.

-
Excellent! How can I add more horizontal spacing between the top of an image and the bottom of the text for each section? –  sonicboom Apr 4 at 13:12
@sonicboom in the first code of my updated answer, you can use something as \par\medskip instead of just \par to increase the vertical separation between subfigures. I am not sure if this is the distance you want to increase; if it's not, please let me know which one is. –  Gonzalo Medina Apr 4 at 13:16
It's perfect cheers. One thing, I have the label 'cw_10_25_50' for the overall figure (not TS as posted above). However, when I try and reference it using the text - In Figure ~\ref{fig:cw_10_25_50} we show the... - it comes up as Figure ?? we show the - when rendered with latex. Any idea what's wrong? –  sonicboom Apr 4 at 13:22
@sonicboom make sure the string used in \ref is exactly the same used in \label; so if \label is only \label{cw_10_25_50}, then you should use \ref{cw_10_25_50} (without the "fig:" prefix). Of course, if you want to use the prefix as in \ref{fig:cw_10_25_50}, then you should also include it in \label, as in \label{fig:cw_10_25_50}. Compile twice after doing the change. If the problem persists, the best thing to do will be to open a fresh new question. –  Gonzalo Medina Apr 4 at 13:27
Great, thanks again Gonzalo. –  sonicboom Apr 4 at 13:32

Gonzalo showed how to use subcaption package to solve the problem. This also uses that package, but shows how stacks and \subcaptionbox can be used to increase the inter-image gap arbitrarily, using the \setstackgap{S}{length} command.

By using the \subcaptionbox variant of subcaption, arbitrary placement of the figures is possible, as also shown in this related answer: Is the following layout possible with the subfigure package?

\documentclass{article}
\usepackage{hyperref}
\usepackage[usestackEOL]{stackengine}
\usepackage{subcaption}
\begin{document}
\begin{figure}[ht]
\centering
\def\figa{\rule{1in}{1.1in}}
\def\figb{\rule{1in}{1.5in}}
\def\figc{\rule{1in}{0.9in}}
\def\capa{subfig a caption}
\def\capb{subfig b caption}
\def\capc{subfig c caption which may be longer}
\savestack{\capfiga}{\subcaptionbox{\capa\label{fg:a}}{\figa}}
\savestack{\capfigb}{\subcaptionbox{\capb\label{fg:b}}{\figb}}
\savestack{\capfigc}{\subcaptionbox{\capc\label{fg:c}}{\figc}}
\setstackgap{S}{12pt}
\Shortstack{\capfiga\\ \capfigb\\ \capfigc}%
\caption{This is my figure\label{fg:}}
\end{figure}
In figure \ref{fg:}, \ref{fg:a}, \ref{fg:b} and \ref{fg:c}...
\end{document}


-