2

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,
  drop fuzzy shadow,
  myminted/#2,#1}


\begin{listingsbox}{myc}{test} 

Examplecode

\end{listingsbox}
1
  • 1
    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!
    – user30471
    Commented Aug 28, 2015 at 11:21

1 Answer 1

4

If I understand correctly, you want to \label the listing and \ref it somewhere. 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,
  drop fuzzy shadow,
  myminted/#2,#1}

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

Examplecode

\end{listingsbox}

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

enter image description here

5
  • If my understanding is wrong, let me know.
    – user11232
    Commented Aug 28, 2015 at 11:53
  • That`s it! Thank you very much for your quick help.
    – henry
    Commented Aug 28, 2015 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.
    – jub0bs
    Commented Aug 28, 2015 at 15:17
  • Hi, now i have a new problem :-), how can i set the line spacing in the tcbbox?
    – henry
    Commented Oct 8, 2015 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
    Commented Oct 8, 2015 at 22:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .