Take the 2-minute tour ×

I am writing a document in which code listings and diagrams appear side-by-side frequently. I am using the listings package for the code and \includegraphics for the diagrams. I want to put them both on the same figure. I tried the subfigure package, but it does not allow verbatim environments inside the \subfigure{} argument.

The fancyvrb package has a workaround for this limitation: Using SaveVerbatim and \BUseVerbatim. However, I prefer to use only the listing package to get uniform styling for my code listings.

The subfigure manual includes some voodoo definition of a subfloat environment which can contain minipages with verbatim content. It is a clumsy solution. I also wonder why this solution was left out of the package itself.

Does anyone know a simple way to make these packages work together? Alt., is there a sub-figures package that is more verbatim-friendly?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

Here's an example using the subcaption package which is included in the caption package bundle. (Note that the \rule command in my example is only a placeholder for \includegraphics.)




    for i:=maxint to 0 do
    { do nothing }
    \caption{A listing}
    \caption{A diagram}
  \caption{A listing and a diagram}


EDIT: The subfigure entry of the TeX Catalogue OnLine states:

This package is now obsolescent: new users should use subfig or subcaption instead.

share|improve this answer
Worked like a charm. Thanks! –  Little Bobby Tables Oct 26 '10 at 14:16
add comment

Your Answer


