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?


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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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