3

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 Liter May 4 '14 at 19:40

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

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}

enter image description here

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}

enter image description here

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.