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.

I want to place 3 subfigures in a figure with two columns. There is one big subfigured placed to the right. The two subfigures on the left should be aligned so that the first is aligned with the top of the big subfigure, and the second is aligned with the caption of the big subfigure.

\begin{figure}[h!]
\begin{minipage}[t]{0.49\linewidth}
\begin{subfigure}{\linewidth}
\begin{lstlisting}[language=c,escapechar=+]
+{public void}+ Method () {
  .. Before
  .. Original code
}
\end{lstlisting}
\caption{Before-Advice}
\label{fig:before}
\end{subfigure}
\begin{subfigure}{\linewidth}
\begin{lstlisting}[language=c,escapechar=+]
+{public void}+ Method () {
  .. Around ( *(Original code) )
}
\end{lstlisting}
\caption{Around-Advice}
\label{fig:around}
\end{subfigure}
\end{minipage}
\begin{minipage}{0.49\linewidth}
\begin{subfigure}{\linewidth}
\begin{lstlisting}[language=c,escapechar=+]
+{public void}+ Method () {
  try {
    .. Original code
    .. After returning
  }
  catch (...) {
    .. After throwing
  }
  finally {
    .. After
  }
}
\end{lstlisting}
\caption{After-Advices}
\label{fig:after}
\end{subfigure}
\end{minipage}
\caption{Advice-Arten}
\label{fig:advices}
\end{figure}
share|improve this question

1 Answer 1

up vote 2 down vote accepted

Here is a possible solution.

\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage{subcaption}
\usepackage{listings}

\begin{document}
\newsavebox{\temp}
\begin{lrbox}{\temp}
\begin{minipage}{\linewidth}  
\begin{lstlisting}[language=c,escapechar=+]
+{public void}+ Method () {
  try {
    .. Original code
    .. After returning
  }
  catch (...) {
    .. After throwing
  }
  finally {
    .. After
  }
}
\end{lstlisting}
\end{minipage}
\end{lrbox} 
\newlength{\tempd}
\newlength{\tempc}
\settoheight{\tempd}{\usebox{\temp}}
\settodepth{\tempc}{\usebox{\temp}}
\addtolength{\tempd}{\tempc}


\begin{figure}[h!]
\begin{minipage}[c]{0.49\linewidth}
\begin{minipage}[t][\tempd][c]{\linewidth}
\begin{lstlisting}[language=c,escapechar=+]
+{public void}+ Method () {
  .. Before
  .. Original code
}
\end{lstlisting}
\subcaption{Before-Advice}
\label{fig:before}

\vfill

\begin{lstlisting}[language=c,escapechar=+]
+{public void}+ Method () {
  .. Around ( *(Original code) )
}
\end{lstlisting}
\end{minipage}
\subcaption{Around-Advice}
\label{fig:around}
\end{minipage}
\begin{minipage}[c][\tempd][c]{0.49\linewidth}%
\usebox{\temp}
\subcaption{After-Advices}
\label{fig:after}
\end{minipage}

\caption{Advice-Arten}
\label{fig:advices}
\end{figure}

This is a reference to subfigure \ref{fig:after}
\end{document}

The idea is to calculate the total height of the longer listing and then set the height of the minipages wrapping the two listings on the left and the listing on the right to such measure. An issue is that we cannot use \caption outside a float, thus we have to use extra minipage as wrappers and to enclose the captions. The package subcaption is used to generate the captions for the subfigures.

enter image description here

share|improve this answer
    
Worked like a charme. Thanks. I would have spent years to get this :) –  Matthias Jan 4 '13 at 7:38
    
Well I just realized that you removed the subfigures. I added them but ended with an error. Is this not possible? –  Matthias Jan 4 '13 at 7:44
    
@Matthias I have edited the solution. I have used the package subcaption to produce the captions for the subfigures. –  Guido Jan 5 '13 at 6:44

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.