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

Amos
  • 145
  • 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 '17 at 14:57

1 Answers1

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}
Torbjørn T.
  • 206,688
  • Thanks! but this looks a bit ugly. Can I have something like a surrounding box with title? – Amos Jun 30 '17 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 https://tex.stackexchange.com/a/256796/586 – Torbjørn T. Jun 30 '17 at 18:19
  • @Amos If you have any more requirements I suggest you ask a new question about it. – Torbjørn T. Jun 30 '17 at 18:20