# How to set the label for listings?

Hi I'm new in Latex and I'm using this code from the Board everything is working, but I don't know how to set the label for the listing with this code

\usepackage[many,minted]{tcolorbox}

\newcommand{\mynewminted}[3]{%
\newminted[#1]{#2}{#3}%
\tcbset{myminted/#1/.style={minted language=#2,minted options={#3}}}}

\mynewminted{myc}{c}{tabsize=2,fontsize=\footnotesize,linenos, numbersep=3mm}

\newtcblisting[auto counter,number within=section,
list inside=mypyg]{listingsbox}[3][]{%
listing only,
title={Listing \thetcbcounter: #3},
list entry={\protect\numberline{\thetcbcounter}#3},
enhanced,
left=6mm,
overlay={\begin{tcbclipinterior}\fill[black!15] (frame.south west)
rectangle ([xshift=6mm]frame.north west);\end{tcbclipinterior}},
colframe=black!35,
myminted/#2,#1}

\begin{listingsbox}{myc}{test}

Examplecode

\end{listingsbox}

• Welcome to TeX.SX! It is easier to help you if you add a minimal working example that takes the form \documentclass{...}\usepackage{....}\begin{document}...\end{document}. If possible, it should compile and have the minimum amount of code needed to illustrate your problem. This makes it much easier for people to troubleshoot your problem - and much more likely that they will! – Andrew Aug 28 '15 at 11:21

If I understand correct, yuo want to \laebl the listing and \ref it some where. If so add the label like:

\begin{listingsbox}{myc,label=mint}{test}


and use \ref{mint} elsewhere.

\documentclass{article}
\usepackage[many,minted]{tcolorbox}

\newcommand{\mynewminted}[3]{%
\newminted[#1]{#2}{#3}%
\tcbset{myminted/#1/.style={minted language=#2,minted options={#3}}}}

\mynewminted{myc}{c}{tabsize=2,fontsize=\footnotesize,linenos, numbersep=3mm}

\newtcblisting[auto counter,number within=section,
list inside=mypyg]{listingsbox}[3][]{%
listing only,
title={Listing \thetcbcounter: #3},
list entry={\protect\numberline{\thetcbcounter}#3},
enhanced,
left=6mm,
overlay={\begin{tcbclipinterior}\fill[black!15] (frame.south west)
rectangle ([xshift=6mm]frame.north west);\end{tcbclipinterior}},
colframe=black!35,
myminted/#2,#1}

\begin{document}
\begin{listingsbox}{myc,label=mint}{test}

Examplecode

\end{listingsbox}

From listing~\ref{mint}, we see a code.
\end{document}


• If my understanding is wrong, let me know. – user11232 Aug 28 '15 at 11:53
• Thats it! Thank you very much for your quick help. – henry Aug 28 '15 at 12:45
• @henry If Harish's answer solved your problem, please consider marking it as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. – jubobs Aug 28 '15 at 15:17
• Hi, now i have a new problem :-), how can i set the line spacing in the tcbbox? – henry Oct 8 '15 at 21:36
• @henry This should be asked a new question certainly. Load \usepackage{setspace} and put before upper = \setstretch{1.5}` in the options. – user11232 Oct 8 '15 at 22:49