0

I would like to add captions to a tcolorbox structure. How can I do so? The standard \caption{} construct does not work in this case. Or is there a way to make the same thing (but with captions) without using tcolorbox?

\begin{tcolorbox}
\begin{verbatim}
{'maxs': [0.0,
  0.0006787988281249935,
  0.00032118164062514,
  0.0001609179687499518],
 'means': [0.0,
  0.00013521044921876194,
  8.352197265622923e-05,
  4.6293782552030614e-05]}
\end{verbatim}
\end{tcolorbox}

enter image description here

2
  • 2
    You can use the title for this. Note that tcolorbox has some tremendous support for listings.
    – user228539
    Nov 18, 2020 at 20:23
  • @sequence -- please have a look at the answer below if it meets the requirement
    – js bibra
    Nov 19, 2020 at 0:46

1 Answer 1

1

Probably something like this as adapted from --

Splitting verbatim inside figure across pages

enter image description here

\documentclass[a4paper]{article}

\usepackage{listings}
\usepackage{tcolorbox}

\tcbuselibrary{breakable,skins,listings}

\newtcblisting[use counter=lstlisting]{cmhlisting}[3][]{%
    width=\textwidth,
    colback=blue!5!white,
    colframe=white!85!black,
    listing only,
    listing options={#1},
    center title,
    %breakable,
    %float,
    %floatplacement=!ht,
    title={\color{black}{\scshape My Caption \thetcbcounter}: ~#2}
}

\begin{document}
\begin{cmhlisting}{Caption with verbatim in  \texttt{tcolorbox}}
'maxs': [0.0,
    0.0006787988281249935,
    0.00032118164062514,
    0.0001609179687499518],
    'means': [0.0,
    0.00013521044921876194,
    8.352197265622923e-05,
    4.6293782552030614e-05]
\end{cmhlisting}
\end{document}

You must log in to answer this question.

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