1

Suppose, I have the grouping of images as specified below.

My problem is that I want to include this kind of image grouping in an environment that uses the subfig package and that subcaption and subfig do not go well together. My question is therefore: How do I replicate the image grouping below in a subfig environment --> e.g. How do I obtain the same result as you shown below but with the \subfloat macro from subfig package?

The goal really is to have a big image in the middle, and 8 images around it.

\documentclass{article}
\usepackage{caption,subcaption}
\usepackage[demo]{graphicx} % demo is just for the example

\begin{document}
\begin{figure}
\centering

\begin{subfigure}[]{.2\textwidth}
    \includegraphics[width=\textwidth,height=2cm]{x}
    \caption{A short figure}

\end{subfigure}\qquad
\begin{subfigure}[]{.2\textwidth}
    \includegraphics[width=\textwidth,height=2cm]{x}
    \caption{A short figure}
\end{subfigure}\qquad

\begin{subfigure}[]{.2\textwidth}
    \includegraphics[width=\textwidth,height=2cm]{x}
    \caption{A short figure}

    \vspace{2ex}

    \includegraphics[width=\textwidth,height=2cm]{x}
    \caption{A short figure}
\end{subfigure}\qquad
\begin{subfigure}[]{.4\textwidth}
\includegraphics[width=\textwidth,height=5cm]{x}
\caption{A tall figure}
\end{subfigure}\qquad
\begin{subfigure}[]{.2\textwidth}
\includegraphics[width=\textwidth,height=2cm]{x}
\caption{A short figure}

\vspace{2ex}

\includegraphics[width=\textwidth,height=2cm]{x}
\caption{A short figure}
\end{subfigure}\qquad

\begin{subfigure}[]{.2\textwidth}
    \includegraphics[width=\textwidth,height=2cm]{x}
    \caption{A short figure}

\end{subfigure}\qquad
\begin{subfigure}[]{.2\textwidth}
    \includegraphics[width=\textwidth,height=2cm]{x}
    \caption{A short figure}
\end{subfigure}\qquad

\caption{The full caption}
\end{figure}
\end{document}

enter image description here

5
  • welcome to tex.se! do i understood you correct that you like to obtain the same result as you shown in question, with use of the \subfloat macro from subfig package?
    – Zarko
    Mar 27, 2019 at 18:48
  • Yes that is exactly what I want - sorry for not having been specific enough.
    – BeSeLuFri
    Mar 27, 2019 at 18:49
  • If you are interested, I have written a version of \subfloat that uses only the subcaption package. Mar 28, 2019 at 5:09
  • Yes, of course I would be interested! Where can I find it? @JohnKormylo
    – BeSeLuFri
    Mar 28, 2019 at 8:38
  • Actually, the subcaption package already provides \subcaptionbox which is roughly equivalent to \subfloat. Apr 1, 2019 at 16:23

2 Answers 2

0

see, if the following solution can help you.

\documentclass{article}
\usepackage{caption}
\usepackage[demo,               % demo is just for the example
            export]{adjustbox}
\usepackage{subfig}
\usepackage{multirow, tabularx}

\begin{document}
    \begin{figure}
\setkeys{Gin}{width=\linewidth, keepaspectratio}

\begin{tabularx}{\linewidth}{@{} *{4}{X} @{}}
    & \subfloat[A short image]{\includegraphics[valign=t]{x}}
        & \subfloat[A short image]{\includegraphics[valign=t]{x}}
            &                                                           \\
\subfloat[A short image]{\includegraphics[valign=t]{x}}
    & \multicolumn{2}{>{\hsize=\dimexpr2\hsize+2\tabcolsep}X}{
        \multirow[t]{2}{=}{\subfloat[A tall image]{\includegraphics[height=78mm,valign=t]{x}}}
                                                    }
        & \subfloat[A short image]{\includegraphics[valign=t]{x}}       \\
\subfloat[A short image]{\includegraphics[valign=t]{x}}
    &   &   & \subfloat[A short image]{\includegraphics[valign=t]{x}}   \\
    & \subfloat[A short image]{\includegraphics[valign=t]{x}}
        & \subfloat[A short image]{\includegraphics[valign=t]{x}}
            &                                                           \\
\end{tabularx}
\caption{The full caption}
    \end{figure}
\end{document}

enter image description here

3
  • yes! it absolutely does. Thank you very much. I have just a small add-on question: see below
    – BeSeLuFri
    Mar 27, 2019 at 19:58
  • I would like to know why the formatting turns out to be slightly different in my environment - see: i.sstatic.net/Pscrs.png
    – BeSeLuFri
    Mar 27, 2019 at 20:05
  • with my code? if you not change anything the only reason which cross my mind is that your latex installation has older packages than mine (i test code with recent miktex suite, upgraded yesterday).
    – Zarko
    Mar 27, 2019 at 20:19
0

As requested, here is a version of \subfloat which is compatible with subcaption.

Adding \sufloatbox is probably overkill, but it is conceivable that #2 could contain code using, for example, \box0. I noticed that both \subfloat and \caption use \@tempboxa, albeit for different purposes.

\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{blindtext}

\newsavebox{\subfloatbox}

\newcommand{\subfloat}[2][\empty]% #1 = caption (optional), #2 = image
{\bgroup
  \captionsetup[subfigure]{font=footnotesize}%
  \savebox\subfloatbox{#2}%
  \begin{subfigure}[t]{\wd\subfloatbox}
    \usebox\subfloatbox
    \ifx\empty#1\relax
      \stepcounter{subfigure}%
    \else
      \caption{#1}%
    \fi
  \end{subfigure}%
\egroup}

\begin{document}
\begin{figure}[htp]
\noindent\rlap{\rule{\textwidth}{0.5pt}}% show baseline
\subfloat[]{\includegraphics[scale=0.3]{example-image-a}}\hfill
\subfloat[\blindtext]{\includegraphics[scale=0.3]{example-image-b}}\hfill
\subfloat{\includegraphics[scale=0.3]{example-image-c}}
\end{figure}
\end{document}

Here is an even simpler version based on \subfigurebox.

\newcommand{\subfloat}[2][\empty]{%
  \ifx\empty#1\relax
    \subcaptionbox*{}{#2}%
    \stepcounter{subfigure}%
  \else
    \subcaptionbox{#1}{#2}%
  \fi}
1
  • Since version 2019/08/31 v1.3 the subcaption package offers \subfloat.
    – user2574
    Jan 20, 2020 at 17:26

You must log in to answer this question.

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