0

I want to insert couples of images which shares one caption into "subfloat",but I got an error, could anyone please help me with this problem? Here is my code:

\documentclass{article}
\usepackage{graphicx}
\usepackage{subfig}
\begin{document}
\begin{figure}
  \centering
  % Requires \usepackage{graphicx}
  \begin{minipage}[t]{0.45\textwidth}
  \centering
  \subfloat[~$2\%$~lifetime sparsity]{
  \includegraphics[width=0.05\textwidth]{figures/second/0_02/001.pdf}\hspace{0.1in}
  \includegraphics[width=0.05\textwidth]{figures/second/0_02/002.pdf}\hspace{0.1in}
  \includegraphics[width=0.05\textwidth]{figures/second/0_02/003.pdf}\hspace{0.1in}
  \includegraphics[width=0.05\textwidth]{figures/second/0_02/004.pdf}\hspace{0.1in}
  \includegraphics[width=0.05\textwidth]{figures/second/0_02/005.pdf}\\
  \includegraphics[width=0.05\textwidth]{figures/second/0_02/006.pdf}\hspace{0.1in}
  \includegraphics[width=0.05\textwidth]{figures/second/0_02/007.pdf}\hspace{0.1in}
  \includegraphics[width=0.05\textwidth]{figures/second/0_02/008.pdf}\hspace{0.1in}
  \includegraphics[width=0.05\textwidth]{figures/second/0_02/009.pdf}\hspace{0.1in}
  \includegraphics[width=0.05\textwidth]{figures/second/0_02/010.pdf}\\
  \includegraphics[width=0.05\textwidth]{figures/second/0_02/011.pdf}\hspace{0.1in}
  \includegraphics[width=0.05\textwidth]{figures/second/0_02/012.pdf}\hspace{0.1in}
  \includegraphics[width=0.05\textwidth]{figures/second/0_02/013.pdf}\hspace{0.1in}
  \includegraphics[width=0.05\textwidth]{figures/second/0_02/014.pdf}\hspace{0.1in}
  \includegraphics[width=0.05\textwidth]{figures/second/0_02/015.pdf}\\
  \includegraphics[width=0.05\textwidth]{figures/second/0_02/016.pdf}\hspace{0.1in}
  \includegraphics[width=0.05\textwidth]{figures/second/0_02/017.pdf}\hspace{0.1in}
  \includegraphics[width=0.05\textwidth]{figures/second/0_02/018.pdf}\hspace{0.1in}
  \includegraphics[width=0.05\textwidth]{figures/second/0_02/019.pdf}\hspace{0.1in}
  \includegraphics[width=0.05\textwidth]{figures/second/0_02/020.pdf}
  }
 % \vspace{0.15in}
  %\caption{~$2\%$~lifetime sparsity}\label{fig:ROI:fig2}
  \end{minipage}
  \begin{minipage}[t]{0.45\textwidth}
  \centering
  \subfloat[~$5\%$~lifetime sparsity]{
  \includegraphics[width=0.05\textwidth]{figures/second/0_05/001.pdf}\hspace{0.1in}
  \includegraphics[width=0.05\textwidth]{figures/second/0_05/002.pdf}\hspace{0.1in}
  \includegraphics[width=0.05\textwidth]{figures/second/0_05/003.pdf}\hspace{0.1in}
  \includegraphics[width=0.05\textwidth]{figures/second/0_05/004.pdf}\hspace{0.1in}
  \includegraphics[width=0.05\textwidth]{figures/second/0_05/005.pdf}\\
  \includegraphics[width=0.05\textwidth]{figures/second/0_05/006.pdf}\hspace{0.1in}
  \includegraphics[width=0.05\textwidth]{figures/second/0_05/007.pdf}\hspace{0.1in}
  \includegraphics[width=0.05\textwidth]{figures/second/0_05/008.pdf}\hspace{0.1in}
  \includegraphics[width=0.05\textwidth]{figures/second/0_05/009.pdf}\hspace{0.1in}
  \includegraphics[width=0.05\textwidth]{figures/second/0_05/010.pdf}\\
  \includegraphics[width=0.05\textwidth]{figures/second/0_05/011.pdf}\hspace{0.1in}
  \includegraphics[width=0.05\textwidth]{figures/second/0_05/012.pdf}\hspace{0.1in}
  \includegraphics[width=0.05\textwidth]{figures/second/0_05/013.pdf}\hspace{0.1in}
  \includegraphics[width=0.05\textwidth]{figures/second/0_05/014.pdf}\hspace{0.1in}
  \includegraphics[width=0.05\textwidth]{figures/second/0_05/015.pdf}\\
  \includegraphics[width=0.05\textwidth]{figures/second/0_05/016.pdf}\hspace{0.1in}
  \includegraphics[width=0.05\textwidth]{figures/second/0_05/017.pdf}\hspace{0.1in}
  \includegraphics[width=0.05\textwidth]{figures/second/0_05/018.pdf}\hspace{0.1in}
  \includegraphics[width=0.05\textwidth]{figures/second/0_05/019.pdf}\hspace{0.1in}
  \includegraphics[width=0.05\textwidth]{figures/second/0_05/020.pdf}
  }
  %\vspace{0.15in}
  %\caption{~$5\%$~lifetime sparsity}\label{fig:ROI:fig3}
  \end{minipage}
\end{figure}
\end{document}
1

You should have the minipage inside \subfloat:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{subfig}
\begin{document}
\begin{figure}

\setkeys{Gin}{height=0.1\textwidth}% just for the example, remove

  \centering

  \subfloat[$2\%$~lifetime sparsity\label{fig:ROI:fig2}]{%
  \begin{minipage}[t]{0.45\textwidth}
  \centering
  \includegraphics[width=0.1\textwidth]{figures/second/0_02/001.pdf}
  \includegraphics[width=0.1\textwidth]{figures/second/0_02/002.pdf}
  \includegraphics[width=0.1\textwidth]{figures/second/0_02/003.pdf}
  \includegraphics[width=0.1\textwidth]{figures/second/0_02/004.pdf}
  \includegraphics[width=0.1\textwidth]{figures/second/0_02/005.pdf}\\
  \includegraphics[width=0.1\textwidth]{figures/second/0_02/006.pdf}
  \includegraphics[width=0.1\textwidth]{figures/second/0_02/007.pdf}
  \includegraphics[width=0.1\textwidth]{figures/second/0_02/008.pdf}
  \includegraphics[width=0.1\textwidth]{figures/second/0_02/009.pdf}
  \includegraphics[width=0.1\textwidth]{figures/second/0_02/010.pdf}\\
  \includegraphics[width=0.1\textwidth]{figures/second/0_02/011.pdf}
  \includegraphics[width=0.1\textwidth]{figures/second/0_02/012.pdf}
  \includegraphics[width=0.1\textwidth]{figures/second/0_02/013.pdf}
  \includegraphics[width=0.1\textwidth]{figures/second/0_02/014.pdf}
  \includegraphics[width=0.1\textwidth]{figures/second/0_02/015.pdf}\\
  \includegraphics[width=0.1\textwidth]{figures/second/0_02/016.pdf}
  \includegraphics[width=0.1\textwidth]{figures/second/0_02/017.pdf}
  \includegraphics[width=0.1\textwidth]{figures/second/0_02/018.pdf}
  \includegraphics[width=0.1\textwidth]{figures/second/0_02/019.pdf}
  \includegraphics[width=0.1\textwidth]{figures/second/0_02/020.pdf}
  \end{minipage}%
  }\hfil
  \subfloat[~$5\%$~lifetime sparsity\label{fig:ROI:fig3}]{%
  \begin{minipage}[t]{0.45\textwidth}
  \centering
  \includegraphics[width=0.1\textwidth]{figures/second/0_05/001.pdf}
  \includegraphics[width=0.1\textwidth]{figures/second/0_05/002.pdf}
  \includegraphics[width=0.1\textwidth]{figures/second/0_05/003.pdf}
  \includegraphics[width=0.1\textwidth]{figures/second/0_05/004.pdf}
  \includegraphics[width=0.1\textwidth]{figures/second/0_05/005.pdf}\\
  \includegraphics[width=0.1\textwidth]{figures/second/0_05/006.pdf}
  \includegraphics[width=0.1\textwidth]{figures/second/0_05/007.pdf}
  \includegraphics[width=0.1\textwidth]{figures/second/0_05/008.pdf}
  \includegraphics[width=0.1\textwidth]{figures/second/0_05/009.pdf}
  \includegraphics[width=0.1\textwidth]{figures/second/0_05/010.pdf}\\
  \includegraphics[width=0.1\textwidth]{figures/second/0_05/011.pdf}
  \includegraphics[width=0.1\textwidth]{figures/second/0_05/012.pdf}
  \includegraphics[width=0.1\textwidth]{figures/second/0_05/013.pdf}
  \includegraphics[width=0.1\textwidth]{figures/second/0_05/014.pdf}
  \includegraphics[width=0.1\textwidth]{figures/second/0_05/015.pdf}\\
  \includegraphics[width=0.1\textwidth]{figures/second/0_05/016.pdf}
  \includegraphics[width=0.1\textwidth]{figures/second/0_05/017.pdf}
  \includegraphics[width=0.1\textwidth]{figures/second/0_05/018.pdf}
  \includegraphics[width=0.1\textwidth]{figures/second/0_05/019.pdf}
  \includegraphics[width=0.1\textwidth]{figures/second/0_05/020.pdf}
  \end{minipage}%
  }

  \caption{Global caption\label{fig:ROI}}
\end{figure}

\end{document}

The demo option and the \setkeys command are just for building an image, since I don't have your images.

enter image description here

  • Great! Thank you! Your answer work very well. – Ellen Liu Apr 22 '17 at 11:47

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.