1

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}
2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.