# How to make a non-float subfigure environment? [duplicate]

I am writing a document class report that has a maximum page limit. I tend to stay away from float environments for tables and figures since I like to have them where I code them in (I try [h], and sometimes it works, sometimes it doesn't). For example, for figures I usually do this:

\begin{center}
\includegraphics[scale=0.6]{figure.png}
\captionof{figure}{caption}
\label{fig:figure}
\end{center}


But I have to make a subfigure for some of my report's pictures. Here is the code for the subfigure:

\begin{figure}[h]
\centering
\begin{subfigure}{0.5\textwidth}
\centering
\includegraphics[width=\linewidth]{figure1.png}
\caption{caption}
\label{fig:figure1}
\end{subfigure}
\begin{subfigure}{0.5\textwidth}
\centering
\includegraphics[width=\linewidth]{figure2.png}
\caption{figure2 caption}
\label{fig:figure2}
\end{subfigure}
\caption{figures}
\label{fig:figures}
\end{figure}


Is there a way to convert this into a non float environment or some package to ensure it will be always where I code it in?

## marked as duplicate by Werner, user31729, Malipivo, jub0bs, Adam LiterMay 4 '14 at 19:40

• I suppose, as long it inside a figure environment it will float anyway? – user31729 May 4 '14 at 18:24
• – Werner May 4 '14 at 18:24
• You can use the H option (from the float package). If the figure doesn't float anymore, I can't see why the subfigures would. – Bernard May 4 '14 at 18:29

One option using minipages and \captionof from the caption package, loaded via the subcaption package:

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

\captionsetup[subfigure]{labelformat=parens,labelsep=space}

\begin{document}

\noindent\begin{minipage}{\textwidth}
\begin{minipage}{0.5\textwidth}
\centering
\includegraphics[width=.9\linewidth]{figure1.png}
\captionof{subfigure}{caption}
\label{fig:figure1}
\end{minipage}%
\begin{minipage}{0.5\textwidth}
\centering
\includegraphics[width=.9\linewidth]{figure2.png}
\captionof{subfigure}{caption}
\label{fig:figure2}
\end{minipage}
\captionof{figure}{figures}
\label{fig:figures}
\end{minipage}

\end{document}


In a comment, a 2x2 grid was requested:

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

\captionsetup[subfigure]{labelformat=parens,labelsep=space}

\begin{document}

\noindent\begin{minipage}{\textwidth}
\begin{minipage}{0.5\textwidth}
\centering
\includegraphics[width=.9\linewidth]{figure1.png}
\captionof{subfigure}{caption}
\label{fig:figure1}
\end{minipage}%
\begin{minipage}{0.5\textwidth}
\centering
\includegraphics[width=.9\linewidth]{figure2.png}
\captionof{subfigure}{caption}
\label{fig:figure2}
\end{minipage}\par
\begin{minipage}{0.5\textwidth}
\centering
\includegraphics[width=.9\linewidth]{figure1.png}
\captionof{subfigure}{caption}
\label{fig:figure3}
\end{minipage}%
\begin{minipage}{0.5\textwidth}
\centering
\includegraphics[width=.9\linewidth]{figure2.png}
\captionof{subfigure}{caption}
\label{fig:figure4}
\end{minipage}
\captionof{figure}{figures}
\label{fig:figures}
\end{minipage}

\end{document}


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

• Thanks for the big help! Is there a way to modify the above so that it will be a 2x2 grid for 4 figures - but same size as these two? – Smitty Shultz May 4 '14 at 22:34
• @SmittyShultz You're welcome! Please see my updated answer for the grid code. – Gonzalo Medina May 4 '14 at 22:42