14

I have 2 subfigures vertically arranged using the subcaption package. I can set the vertical space between the 2 to something specific (using \bigskip or \vspace), but I would like to put as much space as possible between the 2 instead, so that the first subfigure is at the top of the page, and the second one at the bottom (with the caption for the whole figure beneath it) - something like \vfill.

Minimal working example:

\documentclass[10pt,a4paper]{article}
\usepackage{graphicx}
\usepackage{subcaption}

\begin{document}
\begin{figure}
    \begin{subfigure}{\textwidth}
        \centering \rule{4cm}{4cm} % 1st subfigure: \includegraphics{fig}...
    \end{subfigure}
    \par\bigskip % maximise vertical space here instead
    \begin{subfigure}{\textwidth}
        \centering \rule{4cm}{4cm} % 2nd subfigure: \includegraphics{fig}...
    \end{subfigure}
\caption{Some caption}
\end{figure}
\end{document}
7
  • Welcome to TeX.SE! Have you tried \vspace*{\fill} as the "filler" instruction?
    – Mico
    Commented Nov 28, 2013 at 19:48
  • 1
    I just tried it, it doesn't insert any space at all.
    – tave
    Commented Nov 28, 2013 at 19:58
  • What package provides subfigure environment?
    – Sigur
    Commented Nov 28, 2013 at 22:59
  • @Sigur subcaption :-)
    – user11232
    Commented Nov 28, 2013 at 23:01
  • @HarishKumar, strange! I'm getting the error Environment subfigure undefined.
    – Sigur
    Commented Nov 28, 2013 at 23:03

3 Answers 3

15

I put a \vspace*{...} inside the subfigure block, just before \end{subfigure}. It applied the specified amount of spacing between my three subfigures. I did not try it using \fill, but I expect it would have a similar result. I've included a vague snippet of my code below. Hooray for simplicity!

\begin{figure*}[htb]
    \begin{subfigure}[t]{\linewidth}
        \label{}
        \centering\includegraphics[]{image1.eps}
        \caption{}
        \vspace*{2mm}
    \end{subfigure}
    \begin{subfigure}[c]{\linewidth}
        \label{}
        \centering\includegraphics[]{image2.eps}
        \caption{}
        \vspace*{2mm}
    \end{subfigure}
    \begin{subfigure}[b]{\linewidth}
        \label{}
        \centering\includegraphics[]{image3.eps}
        \caption{}
    \end{subfigure}
\end{figure*}
2
  • 2
    Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem.
    – Adam Liter
    Commented Feb 19, 2014 at 19:30
  • It works for me. But starred versions of figure and vspace are not needed. Latex2e tells me that figure* is for double column formats (to span both columns) and tex.stackexchange.com/q/89082/157031 gave info on vspace*. Commented Jan 31, 2019 at 5:10
6

I don't know why \vspace{\fill} is not working in between. Hence this is a work-around using a parbox:

\documentclass[10pt,a4paper]{article}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{showframe}   %% just for demo

\begin{document}
\begin{figure}
    \begin{subfigure}{\textwidth}
       \parbox[t][.48\textheight]{\linewidth}{%  .48 because you have caption below
        \centering \rule{4cm}{4cm}}% 
    \end{subfigure}%
    \par
    \begin{subfigure}{\textwidth}
        \parbox[b][.48\textheight]{\linewidth}{%   %  .48 because you have caption below
        \centering \rule{4cm}{4cm}} 
    \end{subfigure}
\caption{Some caption}
\end{figure}
\end{document}

enter image description here

You can get rid of subfigure and use \parboxes or minipages directly where you can specify the height and width both.

1
  • Thanks for this workaround. It's working, however it still requires some manual tweaking to adjust the size of the \parbox depending on the length of the figure's caption - which I would have preferred to avoid. (NB: I'm keeping the subfigure to label / reference the subfigures)
    – tave
    Commented Nov 29, 2013 at 12:26
3

I post this answer as a note to my future self when I will try to do this again :)

In the following MWE the space between figures is maximized thanks to a stretchable vertical space. In addition to that, for a better look, other two \vspace{\fill} are used to equally distribute the images along the vertical.

To allow the stretchable spaces to have effect, everything is enclosed in a minipage with dimensions equal to the text area.

\documentclass{article}

\usepackage[showframe]{geometry}
\usepackage[demo]{graphicx}
\usepackage{subcaption}

\begin{document}
\begin{figure}[p]
    \begin{minipage}[][\textheight][c]{\textwidth}
        \vspace{\fill}
        \begin{subfigure}{\textwidth}
            \centering
            \includegraphics{first}
            \caption{}
            \label{fig:first}
        \end{subfigure}
        \vfill
        \begin{subfigure}{\textwidth}
            \centering
            \includegraphics{second}
            \caption{}
            \label{fig:second}
        \end{subfigure}
        \vspace{\fill}
    \end{minipage}
\end{figure}
\end{document}

enter image description here

You must log in to answer this question.

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