我想给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}