1

I have the following problem:

Using the subfig package I display 4 images in a 2x2 layout.

\documentclass{article}

\usepackage{subfig,caption}
\usepackage{graphicx}

\begin{document}

\begin{figure}
  \centering
  \subfloat{\includegraphics[width=0.31\textwidth]{img.png}}
  \hspace{1em}
  \subfloat{\includegraphics[width=0.31\textwidth]{img.png}}\\
  \subfloat[Column 1]{\includegraphics[width=0.31\textwidth]{img.png}}
  \hspace{1em}
  \subfloat[Column 2]{\includegraphics[width=0.31\textwidth]{img.png}}
\end{figure}

\end{document}

The result is that the labels start with (c) and (d), positioned under the 3rd and 4rd image. I want the labeling to be (a) and (b). Somehow I need the counter for the caption of subfloat to be reset.

1
  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Jul 29, 2013 at 14:48

3 Answers 3

1

Does that do what you want?

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

\begin{document}

\begin{figure}
\centering
\begin{subfigure}[t]{0.31\textwidth}
    \includegraphics[height=\textwidth,width=\textwidth]{img.png}
    \includegraphics[height=\textwidth,width=\textwidth]{img.png}
    \caption{Column1}
\end{subfigure}
\hspace{1em}
\begin{subfigure}[t]{0.31\textwidth}
    \includegraphics[height=\textwidth,width=\textwidth]{img.png}
    \includegraphics[height=\textwidth,width=\textwidth]{img.png}
    \caption{Column2}
\end{subfigure}
\end{figure}
\end{document}

(I used height=\textwidth only to avoid error messages, beacuse img.png doesn't exist)

enter image description here

I read somewhere that subfig is deprecated and shouldnt be used anymore.

1
  • Yes, this is exactly what I need. It is a simple solution. I would also add some \vspace, but that's easy. I didn't know about the subcaption package and the subfigure command.
    – 3cHeLoN
    Jul 30, 2013 at 15:05
1

The subfig package is deprecated and it is recommended that you do not use it anymore and use subcaption instead. This is what I came up with:

enter image description here

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

\begin{document}
  \begin{figure}
    \centering
    \begin{subfigure}[b]{0.3\textwidth}
      \centering
      \includegraphics[width=\textwidth]{dummy}
      % \caption*{Column 1a}
      \label{fig:1}
    \end{subfigure}%
    ~
    \begin{subfigure}[b]{0.3\textwidth}
      \centering
      \includegraphics[width=\textwidth]{dummy}
      % \caption*{Column 2a}
      \label{fig:2}
    \end{subfigure}%
    \\ % Change row.
    \begin{subfigure}[b]{0.3\textwidth}
      \centering
      \includegraphics[width=\textwidth]{dummy}
      \caption{Column 1b}
      \label{fig:3}
    \end{subfigure}%
    ~
    \begin{subfigure}[b]{0.3\textwidth}
      \centering
      \includegraphics[width=\textwidth]{dummy}
      \caption{Column 2b}
      \label{fig:4}
    \end{subfigure}%
    \caption{The overall caption.}
    \label{fig:all}
  \end{figure}%
\end{document}

If you want captions but not letters in the first row, you can uncomment \caption*.

3
  • 1
    I don't think that subfig is deprecated. It has problems with hyperref, that's all.
    – egreg
    Jul 29, 2013 at 15:20
  • My mistake. I thought it was. Is there any particular reason to prefer subcaption over subfig?
    – sudosensei
    Jul 29, 2013 at 15:23
  • Nice solution, although it is not very compact.
    – 3cHeLoN
    Jul 30, 2013 at 15:06
0

This is basically what I want:

\documentclass{article}

\usepackage{subfig}

\makeatletter
\newcommand{\clearsubcaptcounter}{\setcounter{sub\@captype}{0}}
\makeatother

\begin{document}

\begin{figure}
  \centering
  \subfloat{\rule{4cm}{4cm}}
  \hspace{1em}
  \subfloat{\rule{4cm}{4cm}}\\
  \clearsubcaptcounter
  \subfloat[Column 1]{\rule{4cm}{4cm}}
  \hspace{1em}
  \subfloat[Column 2]{\rule{4cm}{4cm}}
\end{figure}

\end{document}

However, I don't know if this is the cleanest solution since it uses \makeatletter...

You must log in to answer this question.

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