\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}
When I run the above code, I get some errors:
! 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}
How can I fix this problem?
marginfigureis using\marginparthen it cannot escape thetcolorboxso you cannot do this. – daleif Jul 29 '15 at 08:21\marginnotefrom themarginnotepackage inside atcolorbox, if this is an option. – Thomas F. Sturm Jul 29 '15 at 08:36