Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How can I get a layout like the one below in my document?

                enter image description here

With this question, I am looking for:

  1. An answer for the above layout
  2. General advice on which combination of packages is recommended to build sophisticated layouts. By sophisticated layouts I mean layouts where:

    • I can tile figures and subfigures with different sizes but still have them vertically or horizontally aligned.
    • I can have the ability to reference subfigures from the text with links, e.g. "In Fig. 2(a) we have.."

In addressing this problem, I think Mico's answer in this thread: Vertically align subfloats at the top while having subcaptions vertically aligned below the subfloats is releveant, where he said:

According to the latest edition of the l2tabu document, both the subfigure and subfig packages should no longer be used; instead, one should use the subcaption package (from the same author of the caption package).

With this in mind, I thought a good combination of packages to build sophisticated layouts would be:

\usepackage{floatrow}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{calc}
\usepackage{graphicx}

so I used them to try building my layout below, but it didn't work as expected. Below is the code that shows my attempt:

\begin{figure}[t!]%
\begin{floatrow}[2]%
\ffigbox[\FBwidth]% Width of the subfloat:
{%
   \includegraphics[width=0.20\textwidth]{1-1.png}%
   \includegraphics[width=0.20\textwidth]{1-2.png}%
   \includegraphics[width=0.20\textwidth]{1-3.png}%
   \includegraphics[width=0.20\textwidth]{1-4.png}%    
}{\caption{Foo}\label{fig:1}}%
\ffigbox[\Xhsize]%
{%
    \begin{subfloatrow}%
    \ffigbox[\FBwidth]% Width of the subfloat:
    {%
    \includegraphics[width=0.20\textwidth]{2-A.png}%
    }
    {%
      \subcaption{}\label{fig:2-A}%
    }
    \ffigbox[\FBwidth]% Width of the subfloat:
    {%
    \includegraphics[width=0.20\textwidth]{2-B.png}%
    }
    {%
      \subcaption{}\label{fig:2-B}%
    }
    \end{subfloatrow}
}%
{\caption{Results. subref{fig:2-A}: Foo. \subref{fig:1b}: Bar}}
\end{floatrow}%
\end{figure}
share|improve this question
add comment

2 Answers 2

up vote 5 down vote accepted
\documentclass{article}

\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage[labelformat=simple]{subcaption}
\renewcommand\thesubfigure{(\alph{subfigure})} % see subcaption doc

\begin{document}

\begin{figure}
\captionsetup{singlelinecheck=off}
\captionsetup[subfigure]{singlelinecheck=on}
%
\captionbox{Foo\label{fig:1}}[0.42\textwidth][l]{%
   \includegraphics[width=0.20\textwidth]{1-1.png}%
   \phantomsubcaption\label{fig:1a}% Bug: Produces an unwanted space
   \includegraphics[width=0.20\textwidth]{1-2.png}%
   \phantomsubcaption\label{fig:1b}%
\\
   \includegraphics[width=0.20\textwidth]{1-3.png}%
   \phantomsubcaption\label{fig:1c}% Bug: Produces an unwanted space
   \includegraphics[width=0.20\textwidth]{1-4.png}%
   \phantomsubcaption\label{fig:1d}%
}
\captionbox{Results. \subref{fig:2-A}: Foo. \subref{fig:1b}: Bar}{%
  \subcaptionbox{\label{fig:2-A}}{%
    \includegraphics[width=0.20\textwidth]{2-A.png}}
  \subcaptionbox{\label{fig:2-B}}{%
    \includegraphics[width=0.20\textwidth]{2-B.png}}
}%
\end{figure}

\end{document}

Note that we need to use the optional argument of \captionbox here so \\ will work inside it. Furthermore there is a bug in the current version of the caption package so the combination of \phantomsubcaption and \label will produce an unwanted space. This will be fixed in the very next version 3.3 of the caption package. Until then one can place the \phantomcaptions at the end of the box as workaround:

\documentclass{article}

\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage[labelformat=simple]{subcaption}
\renewcommand\thesubfigure{(\alph{subfigure})} % see subcaption doc

\begin{document}

\begin{figure}
\captionsetup{singlelinecheck=off}
\captionsetup[subfigure]{singlelinecheck=on}
%
\captionbox{Foo\label{fig:1}}[0.40\textwidth][l]{%
   \includegraphics[width=0.20\textwidth]{1-1.png}%
   \includegraphics[width=0.20\textwidth]{1-2.png}\\
   \includegraphics[width=0.20\textwidth]{1-3.png}%
   \includegraphics[width=0.20\textwidth]{1-4.png}%
   \phantomsubcaption\label{fig:1a}%
   \phantomsubcaption\label{fig:1b}%
   \phantomsubcaption\label{fig:1c}%
   \phantomsubcaption\label{fig:1d}%
}
\captionbox{Results. \subref{fig:2-A}: Foo. \subref{fig:1b}: Bar}{%
  \subcaptionbox{\label{fig:2-A}}{%
    \includegraphics[width=0.20\textwidth]{2-A.png}}
  \subcaptionbox{\label{fig:2-B}}{%
    \includegraphics[width=0.20\textwidth]{2-B.png}}
}%
\end{figure}

\end{document}

(\captionbox is not documented yet but is available since version 3.2 of the caption package; its syntax is equal to \subcaptionbox but will produce a regular caption instead.)

share|improve this answer
    
Thanks @Alex, and thank by the way for your contributions with the caption and subcaption packages. I have used your packages literally in all my LaTeX documents and papers. About this post: When I run your code, I got the subfigures aligned on the bottom with the figure on the left. I was wondering how you would modify your code above so that the horizontal center of contents of the subfigures align horizontally with the figure on the left (as in the illustration I provided). –  user815423426 Feb 1 '12 at 15:12
add comment

The following duplicates your layout, to some extent, and is flexible:

Figure and subfigure layout

\documentclass{article}
%\usepackage{showframe}% http://ctan.org/pkg/showframe
\usepackage{caption}% http://ctan.org/pkg/caption
\usepackage[labelformat=simple]{subcaption}% http://ctan.org/pkg/subcaption
%\usepackage{graphicx}% http://ctan.org/pkg/graphicx
\newcommand{\pic}[1]{\rule{#1}{#1}}% Fake picture of size #1 x #1
\renewcommand\thesubfigure{(\alph{subfigure})}% Allow sub-figure reference to be correctly printed
\begin{document}

\begin{figure}
  %\setlength{\fboxsep}{-\fboxrule}
  %\fbox{%
    \begin{minipage}[b]{.5\textwidth}
    \centering
      \begin{tabular}{cc}
        \pic{50pt} & \pic{50pt} \\ \pic{50pt} & \pic{50pt}
      \end{tabular}
      \caption{Some figure}\label{fig:1}
    \end{minipage}%
  %}%
  %\fbox{%
    \begin{minipage}[b]{.5\textwidth}
      \begin{subfigure}{.5\textwidth} 
        \centering
        \pic{40pt}
        % Add \par\vspace*{20pt} here and...
        \caption{Subfig1}\label{fig:2a}
      \end{subfigure}%
      \begin{subfigure}{.5\textwidth} 
        \centering
        \pic{40pt}
        % ...here to lower the subcaptions and...
        \caption{Subfig2}\label{fig:2b}
      \end{subfigure} \par \vspace*{20pt} % ...remove them from here
      \caption{Another figure}\label{fig:2}
    \end{minipage}%
  %}
\end{figure}

See Figure~\ref{fig:1} and~\ref{fig:2}. Also see Sub-figures~\ref{fig:2a} and~\ref{fig:2b}.

\end{document}

Both figures are set inside a minipage of width .5\textwidth. That way they still fit precisely within the text block. The left set of figures is constructed within a tabular. The gap between the two columns can be removed/modified using the regular tabular column separator specifications (like @{} for no space, or @{\hspace{<len>}} for a space of <len>).

The sub-figures on the right is pushed up by 20pt to align vertically with the tabular on the left. You may need to vary this, depending on the size of the images contained on the left, as well as those on the right. If you want the sub-figure captions to also be set low, then follow the instructions in the MWE. However, it looks better to me if the sub-captions actually stay with the images.

Referencing works as usual via the correct settings to supcaption (labelformat=simple and setting \thesubfigure appropriately). If you uncomment the showframe package as well as the \fboxes (and \fbox lengths), you'll see how the actual minipage boxes are set:

Subfigure construction

Although I've commented out the use of graphicx, you will most likely use it.


In terms of general advice for sophisticated layouts of figures, floatrow has some really good features. However, as you can see from the example, basic commands and environments like minipage and tabular can work in your favour, allowing optimal control over the layout of document elements.

share|improve this answer
    
This is essentially what I did- you can probably see my deleted answer as you have a high-rep; I don't think it's what the OP wants. –  cmhughes Feb 1 '12 at 4:26
    
@cmhughes: Yes, I tried to send you a suggestion (about using \par\vspace), but you had erased your answer by that time so I couldn't comment. And you were not available in chat, so I thought I'd post something. If the OP was available, one could hash out the details, but we may have to wait until "tomorrow," where-/whenever that may be. –  Werner Feb 1 '12 at 4:30
    
oh well, nevermind :) Looks like other folks like this approach –  cmhughes Feb 1 '12 at 16:14
1  
@cmhughes: We should develop a rep-sharing program... –  Werner Feb 1 '12 at 18:49
1  
lol, don't worry about it :) the important thing is, the OP has a good answer. Plus the trademark-Werner-explanation adds a lot of value :) –  cmhughes Feb 1 '12 at 18:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.