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'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}
share|improve this question
add comment

1 Answer

up vote 9 down vote accepted

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}
share|improve this answer
    
Is it normal, that the listing caption is above? And can I change the listing caption text "Listing" to "Code-Snippet"? –  aphex Dec 27 '12 at 18:49
2  
For the placement of the caption, just write \caption{A caption} after \begin{listing}[ht]. For changing the name of the 'listing caption', see my answer in tex.stackexchange.com/questions/82993/… since this new request duplicates the question there. –  hpesoj626 Dec 27 '12 at 19:21
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.