I am trying to use the subfigure package of LaTeX to display a piece of SQL code. The purpose is similar to Code listing in subfigure, but I'd like syntax highlighting using lstlisting
environment rather than verbatim
. Here is what I'm trying:
\documentclass{article}
\usepackage{subfigure}
\usepackage{listings}
\begin{document}
\begin{table*}[ht]
\subfigure[Query 1]{
\begin{lstlisting}[language=SQL]
SELECT * FROM Table;
\end{lstlisting}
}
\end{table*}
\end{document}
It doesn't compile since the subfigure and verbatim packages clash. The linked post suggests a workaround for the verbatim
environment, but what if I'd like to use lstlisting
?
Best Answer
Box the listing using a
lrbox
:By the way,
subfigure
is an obsolete package; you should usesubfig
orsubcaption
instead. Your code usingsubfig
: