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

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

1 Answers1

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}

js bibra
  • 21,280