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 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.

share|improve this question
    
What is the error given by LaTeX? –  Svante Jul 13 '11 at 7:26
add comment

migrated from stackoverflow.com Jul 14 '11 at 0:44

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

1 Answer

up vote 2 down vote accepted

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.

share|improve this answer
add comment

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.