# Code listing in subfigure

I am trying to use the subfigure package of LaTeX to display a code listing. Here was my first attempt:

\begin{figure}
\subfigure[Standard approach]{
{\footnotesize
\begin{verbatim}
var caps = new Capabilities(Messaging);
\end{verbatim}
}
}
\subfigure[Emerson approach] {
\includegraphics[width=3in]{fig/trust-emerson}
}
\caption{Some caption}
\end{figure}


(All I did was change code where I would have put an \includegraphics line into text.)

I've also tried the equivalent idea using the listings package and replacing the lines in the subfigure with

\begin{lstlisting}
Code
\end{lstlisting}


But that also didn't compile.

-
What is the error given by LaTeX? –  Svante Jul 13 '11 at 7:26

## migrated from stackoverflow.comJul 14 '11 at 0:44

This question came from our site for professional and enthusiast programmers.

your problem is a clash of the subfigure and verbatim packages. One workaround can be the following:

\documentclass[10pt]{report}
\usepackage{graphicx}
\usepackage{subfigure}
\usepackage{fancyvrb}
\begin{document}
\begin{SaveVerbatim}[]{VerbEnv}
var caps = new Capabilities(Messaging);
\end{SaveVerbatim}
\begin{figure}
\subfigure[Standard approach]{
\BUseVerbatim[fontshape=it,fontsize=\footnotesize,fontfamily=courier]{VerbEnv}
}
\subfigure[Emerson approach] {
\includegraphics[width=2in]{fig.eps}
}
\caption{caption }
\end{figure}
\end{document}


For details see the documentation for the fancyvrb package.

-