1
\begin{tcolorbox}
\begin{lstlisting} [caption = {C Code}, captionpos=b, label = {Listing3}, abovecaptionskip=12pt]
int a ,b;
int value = 20;
\end{lstlisting}
\end{tcolorbox}

I am using the above code for listing. In current situation, caption is written inside the tcolorbox. I want to write it outside the box. what command I should add ?

sara lee
  • 41
  • 3
  • Welcome to TeX.SX! That you've no answer after two days could be because you used the wrong tag. But it would also help a lot, if you'd show a minimal working example instead of a code snippet only. And what do you mean with “outside the box”? Completely outside or something like a header box as shown in chapter 17 of the tcolorbox manual? – cabohah Oct 31 '23 at 09:14
  • 1
    Just a hint https://tex.stackexchange.com/questions/142476/caption-package-destroys-center-varwidth/142481#142481 – MadyYuvi Oct 31 '23 at 09:49

1 Answers1

1

Hope this is the one you expects:

\documentclass{book}
\usepackage{tcolorbox}
\usepackage{listings}

\usepackage[labelfont=bf,font=footnotesize]{caption} \captionsetup{format=plain}

\usepackage{capt-of}

\begin{document}

\begin{tcolorbox} \begin{lstlisting} [ label = {Listing3}, abovecaptionskip=12pt] int a ,b; int value = 20; \end{lstlisting} \end{tcolorbox} \captionof{lstlisting}[C Code]{C Code}

\end{document}

enter image description here

As you are not provided full MWE, so I used the standard book class file

MadyYuvi
  • 13,693
  • Thanks. It works. In order to ref this list , I am using \ref{Listing3}, means lable. First time it picks exact reference ,while refering second list by new label .Then there is label of first list (not considering new label) 2)\captionof{lstlisting}[C Code]{C Code} means caption , but why it appears twice? 3) For new caption, I have written \begin{lstlisting} [ label = {Listing4}, abovecaptionskip=12pt] ......as \captionof{lstlisting}[C++ Code]{C++ Code} – sara lee Nov 05 '23 at 17:40