3

I can see that figures work without any error within theorem environments defined with the amsthm package, but it does not work in tcolorbox theorem environments. Rather, it throws the error "! LaTeX Error: Float(s) lost." Why is this so? Also, how would I work around this? Here's a minimal example

\documentclass[12pt, letter]{article}

\usepackage{amsthm}
\usepackage{tikz}
\usepackage{tcolorbox}

\newtheorem{thm}{Theorem}

\tcbuselibrary{theorems}
\newtcbtheorem[number within=section]{mytheo}{My Theorem}%
{colback=green!5, colframe=green!35!black, fonttitle=\bfseries}{th}

\begin{document}

\begin{thm}
Test.
\begin{figure}[h]
    \caption{An empty figure}
\centering
Test.
\end{figure}
\end{thm}



\begin{mytheo}{Title}{stuff}
    ASDF testing stuff!!!
\begin{figure}[h]
    \caption{An empty figure}
\centering
Test.
\end{figure}
\end{mytheo}


\end{document}
0

1 Answer 1

4

Boxes cannot contain floats. Use \begin{figure}[H] (requires \usepackage{float}). This translates the float to a minipage which is allowed to appear inside a box.

\documentclass[12pt, letter]{article}

\usepackage{amsthm}
\usepackage{float}
\usepackage{tikz}
\usepackage{tcolorbox}

\newtheorem{thm}{Theorem}

\tcbuselibrary{theorems}
\newtcbtheorem[number within=section]{mytheo}{My Theorem}%
{colback=green!5, colframe=green!35!black, fonttitle=\bfseries}{th}

\begin{document}

\begin{thm}
Test.
\begin{figure}[h]
    \caption{An empty figure}
\centering
Test.
\end{figure}
\end{thm}



\begin{mytheo}{Title}{stuff}
    ASDF testing stuff!!!
\begin{figure}[H]
    \caption{An empty figure}
\centering
Test.
\end{figure}
\end{mytheo}


\end{document}

enter image description here

You must log in to answer this question.

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