如何在 tcolorbox 环境中使用 marginfigure 环境?

如何在 tcolorbox 环境中使用 marginfigure 环境?
\documentclass{book}
\usepackage[demo]{graphicx}
\usepackage[paperwidth=170mm, paperheight=240mm, left=42pt, top=40pt, textwidth=280pt, marginparsep=20pt, marginparwidth=100pt, textheight=560pt, footskip=40pt]{geometry}
\usepackage{lipsum}
\usepackage{sidenotes}
\usepackage[many]{tcolorbox}
\begin{document}
A test
\begin{tcolorbox}
\lipsum[1]
\begin{marginfigure}%[!h]
\includegraphics[width=\linewidth]{fig1}
\caption{A test caption}
\label{fig1}
\end{marginfigure}
\end{tcolorbox}

\end{document}

当我运行上述代码时,出现一些错误:

! LaTeX Error: Not in outer par mode.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.15 \end{marginfigure}
? r
OK, entering \nonstopmode...
! Undefined control sequence.
<argument> \@marbox
l.15 \end{marginfigure}

我该如何解决这个问题?

答案1

另一种方式,在 marginfigure 中框出:

\documentclass{book}
\usepackage[demo]{graphicx}
\usepackage[paperwidth=170mm, paperheight=240mm, left=42pt, top=40pt, textwidth=280pt, marginparsep=20pt, marginparwidth=100pt, textheight=560pt, footskip=40pt]{geometry}
\usepackage{lipsum}
\usepackage{sidenotes}
\usepackage[many]{tcolorbox}
\begin{document}
A test

\lipsum[1]
\begin{marginfigure}%[!h]
\begin{tcolorbox}
\includegraphics[width=\linewidth]{fig1}
\caption{A test caption}
\label{fig1}
\end{tcolorbox}
\end{marginfigure}


\end{document}

相关内容