![tcolorbox 的标题](https://linux22.com/image/424271/tcolorbox%20%E7%9A%84%E6%A0%87%E9%A2%98.png)
我想给tcolorbox
结构添加标题。我该怎么做?标准\caption{}
构造在这种情况下不起作用。或者有没有办法在不使用的情况下做同样的事情(但带有标题)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}
答案1
可能是这样的,改编自——
\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}