5

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.

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

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.

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.