7

I would like to place two figures, where each figure has subfigures next to each other. I tried with minipage, but tex does not like the \subfigure as Not in outer par mode. Is there any way to place figures with subfigures next to each other?

\begin{figure*}[htbp]


\begin{minipage}[hbt]{0,49\textwidth}

\begin{figure}
\subfigure[Subfigure 1.1]{
\label{fig:subfig1_1}
\includegraphics[scale=0.42]{graphs/sub_1_1.pdf}
}

\subfigure[Sub 1.2] {
\label{fig:subfig1_2}
\includegraphics[scale=0.42]{graphs/sub_1_2.pdf}
}
}
\label{fig:subfigure1} 
\caption{Subfigure 1}
\end{figure}
\end{minipage}




\begin{minipage}[hbt]{0,49\textwidth}
%... as above
\end{minipage}
\end{figure*}
2

2 Answers 2

4

You can't put a floating object inside a minipage, but you can place minipages inside a floating object. I notice that you are using the obsolete subfigure package; you should use subfig or subcaption instead.

Below there are two approaches; the first one using the subfig package, and the other one using the subcaption package:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{subfig} % Needs subfig for this example.

\begin{document}

\begin{figure}
\begin{minipage}{.48\textwidth}
\centering
\subfloat[]{\includegraphics[width=.4\linewidth]{fig1}}\quad
\subfloat[]{\includegraphics[width=.4\linewidth]{fig2}}
\caption{First figure with two subfigures}
\label{fig:testa}
\end{minipage}\hfill
\begin{minipage}{.48\textwidth}
\centering
\subfloat[]{\includegraphics[width=.4\linewidth]{fig3}}\quad
\subfloat[]{\includegraphics[width=.4\linewidth]{fig4}}
\caption{Second figure with two subfigures}
\label{fig:testb}
\end{minipage}
\end{figure}

\end{document} 

enter image description here

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

\begin{document}

\begin{figure}
\begin{minipage}{.48\textwidth}
\centering
\subcaptionbox{}{\includegraphics[width=.4\linewidth]{fig1}}\quad
\subcaptionbox{}{\includegraphics[width=.4\linewidth]{fig2}}
\caption{First figure with two subfigures}
\label{fig:testa}
\end{minipage}\hfill
\begin{minipage}{.48\textwidth}
\centering
\subcaptionbox{}{\includegraphics[width=.4\linewidth]{fig3}}\quad
\subcaptionbox{}{\includegraphics[width=.4\linewidth]{fig4}}
\caption{Second figure with two subfigures}
\label{fig:testb}
\end{minipage}
\end{figure}

\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.

3
  • +1 what is the pros and cons betweem both approaches? Commented Oct 23, 2012 at 16:49
  • 1
    @ガベージコレクタ this question and its answers give a good comparison. Commented Oct 23, 2012 at 17:43
  • @Speravir yes it was a typo. I had subcaption in both examples (the problems of copy-paste). Commented May 6, 2013 at 22:39
2

Since figure is a floating object and minipages are not, you can't use figures inside minipages. One method is to avoid using figure and use the captionof from caption/subcation (or capt-of) package.

Code:

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


\begin{document}
\noindent
\begin{minipage}[t]{0.49\linewidth}%
\begin{minipage}[t]{0.49\textwidth}%
\includegraphics[width=\textwidth]{example-image-a}%
\captionof{subfigure}{sub figure - 1}
\end{minipage}%
\hfill
\begin{minipage}[t]{0.49\textwidth}%
\includegraphics[width=\linewidth]{example-image-b}
\captionof{subfigure}{sub figure - 2} 
\end{minipage}
\captionof{figure}{figure one}
\end{minipage}%
\setcounter{subfigure}{0}
\hfill
\begin{minipage}[t]{0.49\linewidth}%
\begin{minipage}[t]{0.49\textwidth}%
\includegraphics[width=\textwidth]{example-image-c}%
\captionof{subfigure}{sub figure - 1}
\end{minipage}%
\hfill
\begin{minipage}[t]{0.49\textwidth}%
\includegraphics[width=\linewidth]{example-image}
\captionof{subfigure}{sub figure - 2}
\end{minipage}
\captionof{figure}{figure two}
\end{minipage}%


\end{document} 

enter image description here

4
  • It's not appropriate to use hbt in the optional argument of minipage (you can use t, b, or c). Commented Oct 23, 2012 at 16:35
  • @GonzaloMedina My bad. I copied it as such from the OP's code and overlooked. Thanks for noting.
    – user11232
    Commented Oct 23, 2012 at 21:40
  • +1 Harish :) have you tried cross referencing a subfigure using this method? It produces the incorrect numbers--yikes!
    – cmhughes
    Commented Mar 1, 2015 at 19:16
  • @cmhughes: No Chris. but I will do today after dome time. :-)
    – user11232
    Commented Mar 1, 2015 at 23:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .