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*}
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.

  • +1 what is the pros and cons betweem both approaches? – kiss my armpit Oct 23 '12 at 16:49
  • 1
    @ガベージコレクタ this question and its answers give a good comparison. – Gonzalo Medina Oct 23 '12 at 17:43
  • @Speravir yes it was a typo. I had subcaption in both examples (the problems of copy-paste). – Gonzalo Medina May 6 '13 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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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