[Tex/LaTex] Reference Code snippet in latex using minted

cross-referencingminted

I'm not really sure how to reference a code snippet in my text. I need also a caption for the code. The only working way I found is wrapping the minted in a figure. The problem is that I want to distinguish figures from code snippets..

\begin{figure} [ht]
\centering
\begin{minted}[mathescape,
               numbersep=5pt,
               frame=lines,
               framesep=5mm]{sql}
natural join library.Book with amazon.Book as jointarge.BookCollection
with keep attributes library.Book.title
\end{minted}
\caption{A Caption}
\label{fig:Figure}
\end{figure}

Best Answer

Use listing environment instead.

\documentclass[]{article}

\usepackage{minted}

\begin{document}
\begin{listing}[ht]
\begin{minted}[mathescape,
               numbersep=5pt,
               frame=lines,
               framesep=5mm]{sql}
natural join library.Book with amazon.Book as jointarge.BookCollection
with keep attributes library.Book.title
\end{minted}
\caption{A Caption}
\label{lst:Listing}
\end{listing}
Listing \ref{lst:Listing} contains an example of a listing.
\end{document}
Related Question