Graphics, Figures & Tablessubcaption shared by subfigures within float

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
lauraf
Posts: 29
Joined: Tue Jan 13, 2009 12:44 pm

subcaption shared by subfigures within float

Post by lauraf »

Hi all,

I am a bit confused about the use of ContinuedFloat and the subcaption package. I have:

Code: Select all

\documentclass{book}

\usepackage{hyperref}

\usepackage{caption}
\usepackage[list=on]{subcaption}

\begin{document}

\begin{figure}
    \centering
    \unitlength .5cm
    \subcaptionbox{SubFig1\label{fig:testsub1}}
    {%
        \begin{picture}(10,10)
            \put(0,0){\line(1,1){10}}
        \end{picture}
    }
    \par
    \vspace{10pt}
    \subcaptionbox{SubFig2\label{fig:testsub2}}
    {%
        \begin{picture}(10,10)
            \put(0,10){\line(1,-1){10}}
        \end{picture}
    }
    \caption{Testfigures}
    \label{fig:test2}
\end{figure}

\begin{figure}
\ContinuedFloat
    \centering
    \unitlength .5cm
    \subcaptionbox{SubFig1\label{fig:testsub1}}
    {%
        \begin{picture}(10,10)
            \put(0,0){\line(1,1){10}}
        \end{picture}
    }
    \par
    \vspace{10pt}
    \subcaptionbox{SubFig2\label{fig:testsub2}}
    {%
        \begin{picture}(10,10)
            \put(0,10){\line(1,-1){10}}
        \end{picture}
    }
    \caption{Testfigures}
    \label{fig:test2}
\end{figure}

\end{document}
So for each float I have two subfigures. As it is now, each subfigure has its own subcaption, but what I want instead is for each float to have one subcaption shared by the two subfigures.

I have tried moving things around in various ways but am totally confused on what should go where! Any help much appreciated.

Many thanks,
Laura
Last edited by lauraf on Thu Jun 11, 2009 5:31 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

subcaption shared by subfigures within float

Post by sommerfee »

lauraf wrote:So for each float I have two subfigures. As it is now, each subfigure has its own subcaption, but what I want instead is for each float to have one subcaption shared by the two subfigures.
I'm sorry, but I'm not sure if I have understood you correctly.

If you want to have no sub-captions (but only a single figure caption), just don't use \subcaptionbox at all.

If you want to have a single sub-caption for two pictures, just put the two pictures inside a single \subcaptionbox.

HTH,
Axel
lauraf
Posts: 29
Joined: Tue Jan 13, 2009 12:44 pm

subcaption shared by subfigures within float

Post by lauraf »

Hi Axel,

Thanks, sorry my post wasn't clear :oops:

What I want is a single sub-caption for two pictures. I had tried putting the two pictures inside a single \subcaptionbox, as you suggest. For example:

Code: Select all

   \subcaptionbox{SubFig1\label{fig:testsub1}}
    {%
        \begin{picture}(10,10)
            \put(0,0){\line(1,1){10}}
        \end{picture}
    \par
    \vspace{10pt}
        \begin{picture}(10,10)
            \put(0,10){\line(1,-1){10}}
        \end{picture}
    }
The problem with this is that it seems to ignore the \par instruction (and I need the two pictures to be one on top of the other rather than side by side). I am sure there is a pretty obvious way of doing this but I can't seem to figure it out (LaTeX newbie...)!

Many thanks!
Laura
User avatar
sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

subcaption shared by subfigures within float

Post by sommerfee »

lauraf wrote:The problem with this is that it seems to ignore the \par instruction (and I need the two pictures to be one on top of the other rather than side by side).
Oh yes, you are right, and I'm sorry, I totally forgot this. \subcaptionbox uses a horizontal box inside to measure its width and there vertical stuff (like \\, \par etc.) will get ignored.

I should have mentioned it in the subfigure documentation, will fix this for the next release.
I am sure there is a pretty obvious way of doing this
You could use a subfigure environment for this. A subfigure uses a minipage internally and inside it vertical stuff is allowed, e.g.:

Code: Select all

\documentclass{book}

\usepackage{hyperref}

\usepackage{caption}
\usepackage[list=on]{subcaption}

\begin{document}

\begin{figure}
  \begin{subfigure}{\linewidth}
    \centering
    \unitlength .5cm
        \begin{picture}(10,10)
            \put(0,0){\line(1,1){10}}
        \end{picture}
    \par
    \vspace{10pt}
        \begin{picture}(10,10)
            \put(0,10){\line(1,-1){10}}
        \end{picture}
    \caption{SubFig1 and SubFig2\label{fig:testsub1}}
  \end{subfigure}
  \caption{Testfigures}
  \label{fig:test1}
\end{figure}

\begin{figure}
\ContinuedFloat
  \begin{subfigure}{\linewidth}
    \centering
    \unitlength .5cm
        \begin{picture}(10,10)
            \put(0,0){\line(1,1){10}}
        \end{picture}
    \par
    \vspace{10pt}
        \begin{picture}(10,10)
            \put(0,10){\line(1,-1){10}}
        \end{picture}
    \caption{SubFig3 and SubFig4\label{fig:testsub3}}
  \end{subfigure}
  \caption{Testfigures (continued)}
  \label{fig:test2}
\end{figure}

\end{document}
If you have questions about this please don't hesitate to ask.

HTH,
Axel
Post Reply