图形和 tcolorbox 出现浮动丢失错误

图形和 tcolorbox 出现浮动丢失错误

由于某种原因,每当我尝试将图形插入此 tcolorbox 时,都会遇到此错误:Float(s) lost.

我见过 tcolorboxes 支持图形的例子,所以我想知道这是否与 tcbtheorem 或 tcblisting(我当前正在使用的盒子)有关,或者是否与我没有正确设置的 tcolorbox 设置有关。

以下是所讨论的 tcolorboxes 的代码:

% listings box
\newtcblisting[auto counter, number within=section, list inside=examplelist]{tcbcodex}[2][]{%
        colback=gray!5, colbacktitle=gray!40, coltitle=black,
        frame hidden, arc=2pt, titlerule=0pt, toptitle=2pt, bottomtitle=2pt,
        fonttitle=\bfseries, breakable, enhanced, parbox=false,
        segmentation style={solid, draw=gray!20, line width=1pt},
        comment and listing,
        title=Example~\thetcbcounter,
        comment={#2},#1
}

% theorem box
\newtcbtheorem[number within=section, list inside=definitionlist]{tcbdefinition}{Definition}{%
        colback=red!5, colbacktitle=red!20, coltitle=black,
        frame hidden, arc=2pt, titlerule=0pt, toptitle=2pt, bottomtitle=2pt,
        fonttitle=\bfseries, breakable, enhanced, parbox=false
}{def}

这是我在编译和出现错误之前拥有的两个框的代码:

% example box
\begin{tcbexample}[name = Test Example, listing options = {language = Python}]
{Here is a comment.
\begin{figure}[ht]
\includegraphics[width=10cm]{foo.png}
\centering\caption{Here is a caption.}
\end{figure}
And there goes my figure.}
Here is some code.
\end{tcbexample}

% definition theorem box
\begin{definition}[Definition]
Here I will place a figure.
\begin{figure}[ht]
\includegraphics[width=10cm]{foo.png}
\centering\caption{Here is a caption.}
\end{figure}
And there goes my figure.
\end{definition}

有人知道为什么会发生这种情况以及如何解决吗?谢谢!

相关内容