1

I've tried

\begin{listing}
\begin{minted}{SQL}
SELECT COUNT(*) FROM lineitem
WHERE l_shipdate <= :shipdate
\end{minted}
\label{test}
\end{listing}

but it doesn't work. \cref{test} reference to the parent section

1
  • 2
    Welcome to TeX.SX! Please help us (and also you) and add a minimal working example (MWE), that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass and ending with \end{document}.
    – Bobyandbob
    Jun 30, 2017 at 14:57

1 Answer 1

2

You need something that has a number, i.e. a \caption:

enter image description here

\documentclass{article}
\usepackage{minted}
\usepackage{cleveref}

\begin{document}
\begin{listing}
\begin{minted}{SQL}
SELECT COUNT(*) FROM lineitem
WHERE l_shipdate <= :shipdate
\end{minted}
\caption{Testing}
\label{test}
\end{listing}
See \cref{test}.
\end{document}
3
  • Thanks! but this looks a bit ugly. Can I have something like a surrounding box with title?
    – Amos
    Jun 30, 2017 at 17:42
  • @Amos You can add a simple frame (or rather, lines above and below) with \begin{minted}[frame=lines]{SQL}, but the manual mentions that both the tcolorbox and mdframed packages have interfaces for minted, so in that sense there is a lot of flexibility with regard to frames. To move the caption to the top, see tex.stackexchange.com/a/256796/586 Jun 30, 2017 at 18:19
  • @Amos If you have any more requirements I suggest you ask a new question about it. Jun 30, 2017 at 18:20

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.