在另一个 tcolorbox 中浮动 tcolorbox 环境

在另一个 tcolorbox 中浮动 tcolorbox 环境

我在序言中定义了一个新环境\newtcolorbox。如果我在文档中调用它,我就可以使用它。没问题!

\documentclass{article}

% Standard Packages
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage{graphicx, subfig}
\graphicspath{{img/}}
\usepackage[theorems,skins,breakable]{tcolorbox}
\tcbuselibrary{breakable, skins, raster} 
\usepackage{lipsum}

\newtcolorbox[blend into=figures]{myfigure}[2][]{float=htb,capture=hbox,
blend before title=dash hang,title={#2},every float=\centering,#1}

\begin{document}

\begin{tcolorbox}[breakable]
\lipsum{}
\end{tcolorbox} 

\begin{myfigure}{A tcolorbox figure with quite a long title}
    \includegraphics[height=5cm]{modulation.png}
\end{myfigure}

\end{document}

现在我想整合我的形象-环境彩色盒子, 像这样:

\begin{tcolorbox}[breakable]
    \lipsum{}
    \begin{myfigure}{A tcolorbox figure with quite a long title}
        \includegraphics[height=5cm]{modulation.png}
    \end{myfigure}
\end{tcolorbox} 

为什么这不可能?错误消息的含义是什么:

  • Not in outer par mode. \end{myfigure}

  • Undefined control sequence. \end{myfigure}

  • Missing number, treated as zero. \end{myfigure}

有人能帮我正确配置它吗?

答案1

您不能在可破坏框内放置浮动。但是,当您允许将选项传递给浮动框时,您可以执行以下操作(禁用浮动一次):

breakable box with float

\documentclass{article}

% Standard Packages
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage[theorems,skins,breakable]{tcolorbox}
\tcbuselibrary{breakable, skins, raster} 
\usepackage{lipsum}

\newtcolorbox[blend into=figures]{myfigure}[2][]{float=htb,capture=hbox,
blend before title=dash hang,title={#2},every float=\centering,#1}

\begin{document}

\begin{tcolorbox}[breakable]
\lipsum{}
\begin{myfigure}[nofloat]{A tcolorbox figure with quite a long title}
    \includegraphics[height=5cm]{example-image}
\end{myfigure}
\end{tcolorbox} 

\end{document}

相关内容