4

I am trying to arrange two rows of sub-figures using subfig and floatrow. The captions are aligned as I wish and the vertical alignment of the objects is also fine. However, I cannot figure out how to get the horizontal spacing between the sub-figures even. In the bottom row, there is no problem: 2 figures with some space between. Fine. In the top row, however, there is more space between the first two figures than there is between the second and third figures. And I cannot figure out why.

5 sub-figures in 2 rows

What am I missing?

\documentclass{article}
\usepackage{graphicx,subfig}
\usepackage[heightadjust=all,valign=c]{floatrow}
\usepackage{fr-subfig}

\begin{document}

  \begin{figure}[!htbp]
    \captionsetup[subfigure]{justification=centering}
    \floatbox{figure}{%
      \caption{%
        Components of the system: Penguins (\ref{fig:a}), Jumpers (\ref{fig:b}), Thingies (\ref{fig:c}), Cabbages (\ref{fig:d}) and Nuclear Warheads (\ref{fig:e})%
      }\label{fig:x}%
    }{%
  \begin{subfloatrow}%
    \subfloat[Penguins were here and here and here]{%
      \includegraphics[height=.1\textheight]{example-image-a}\label{fig:a}}
    \qquad
    \subfloat[Penguin]{%
      \includegraphics[height=.15\textheight]{example-image-b}\label{fig:b}}
    \qquad
    \subfloat[Penguin]{%
      \includegraphics[height=.125\textheight]{example-image-a}\label{fig:c}}
  \end{subfloatrow}

  \begin{subfloatrow}
    \subfloat[Penguin]{%
      \includegraphics[height=.15\textheight]{example-image-b}\label{fig:d}}
    \qquad
    \subfloat[Penguins were here, there and everywhere!]{%
      \includegraphics[height=.2\textheight]{example-image-a}\label{fig:e}}
  \end{subfloatrow}}
\end{figure}

\end{document}

Note that I am aware of alternatives to subfig. If no solution is available for subfig, I'll hack something for now and look into other options for the future.

4

Update

The subfloatrowsep, floatrowsep keys give you control on the horizontal separation between subfloats (floats) when using floatrow; however, simply using something like

\thisfloatsetup{subfloatrowsep=qquad}

in your current code will not produce the desired result since you are using \subfloat (from the subfig package). The solution is not to use \subfloat and use floatrow's \ffigbox instead. This makes

\thisfloatsetup{subfloatrowsep=qquad}

behave as expected and also solves a problem with the counters (further discussed in How can I get correct labelling of sub-figures with subfig and floatrow?).

\documentclass{article}
\usepackage{graphicx,subfig}
\usepackage[heightadjust=all,valign=c]{floatrow}
\usepackage{fr-subfig}

\begin{document}

  \thisfloatsetup{subfloatrowsep=qquad}
  \begin{figure}[!htbp]
    \captionsetup[subfigure]{justification=centering}
      \ffigbox{%
  \begin{subfloatrow}[3]%
    \ffigbox[\FBwidth]{\caption{Penguins were here and here and here}\label{fig:a}}{%
      \includegraphics[height=.1\textheight]{example-image-a}}
    \ffigbox[\FBwidth]{\caption{Penguin}\label{fig:b}}{%
      \includegraphics[height=.15\textheight]{example-image-b}}
    \ffigbox[\FBwidth]{\caption{Penguin}\label{fig:c}}{%
      \includegraphics[height=.125\textheight]{example-image-a}}
  \end{subfloatrow}

  \begin{subfloatrow}
    \ffigbox[\FBwidth]{\caption{Penguin}\label{fig:d}}{%
      \includegraphics[height=.15\textheight]{example-image-b}}
    \ffigbox[\FBwidth]{\caption{Penguins were here, there and everywhere!}\label{fig:e}}{%
      \includegraphics[height=.2\textheight]{example-image-a}}
  \end{subfloatrow}%
      }{%
        \caption{Components of the system: Penguins (\ref{fig:a}), Jumpers (\ref{fig:b}), Thingies (\ref{fig:c}), Cabbages (\ref{fig:d}) and Nuclear Warheads (\ref{fig:e})\label{fig:x}}%
    }
\end{figure}

\end{document}

The output:

enter image description here

Initial version

I've also had problems with horizontal positioning of figures using floatrow and the floatrowsep, subfloatrowsep keys seem to not always behave as expected.

One option that I've found to work in problematic cases is to kill the default separation with subfloatrowsep=none and then use \quad or any other spacing command to manually control the separation (one would think that subfloatrowsep=quad would handle this automatically, but this is not always the case). Anyways, my suggestion:

\documentclass{article}
\usepackage{graphicx,subfig}
\usepackage[heightadjust=all,valign=c]{floatrow}
\usepackage{fr-subfig}

\begin{document}
  \thisfloatsetup{subfloatrowsep=none}
  \begin{figure}[!htbp]
    \captionsetup[subfigure]{justification=centering}
    \floatbox{figure}{%
      \caption{%
        Components of the system: Penguins (\ref{fig:a}), Jumpers (\ref{fig:b}), Thingies (\ref{fig:c}), Cabbages (\ref{fig:d}) and Nuclear Warheads (\ref{fig:e})%
      }\label{fig:x}%
    }{%
  \begin{subfloatrow}%
    \subfloat[Penguins were here and here and here]{%
      \includegraphics[height=.1\textheight]{example-image-a}\label{fig:a}}%
    \qquad
    \subfloat[Penguin]{%
      \includegraphics[height=.15\textheight]{example-image-b}\label{fig:b}}
    \qquad
    \subfloat[Penguin]{%
      \includegraphics[height=.125\textheight]{example-image-a}\label{fig:c}}
  \end{subfloatrow}

  \begin{subfloatrow}
    \subfloat[Penguin]{%
      \includegraphics[height=.15\textheight]{example-image-b}\label{fig:d}}
    \qquad
    \subfloat[Penguins were here, there and everywhere!]{%
      \includegraphics[height=.2\textheight]{example-image-a}\label{fig:e}}
  \end{subfloatrow}}
\end{figure}

\end{document}

enter image description here

2
  • Thank you! I haven't tested this yet, but it makes sense. I tried all kinds of things in \floatsetup... and I couldn't figure out why keys which the docs say change horizontal spacing seemed to have zero effect, while other things seemed to work more-or-less as advertised. Since I'd never used the package, I assumed that must be me... Thanks again. – cfr Feb 19 '15 at 4:08
  • Though I may also have been trying to change the wrong thing... :(. – cfr Feb 19 '15 at 4:10

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.