0
\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?

  • If marginfigure is using \marginpar then it cannot escape the tcolorbox so you cannot do this. – daleif Jul 29 '15 at 8:21
  • Isn't there really any other way to do this? – Sisabe Jul 29 '15 at 8:32
  • It would be possible to use \marginnote from the marginnote package inside a tcolorbox, if this is an option. – Thomas F. Sturm Jul 29 '15 at 8:36
  • @Sisabe this is one of the LaTeX limitations. Certain constructions cannot be used inside other constructions. The solution Thomas mention might be better as it can usually come out of boxes. But it does not automatically move if it gets too close to another margin thing. – daleif Jul 29 '15 at 8:40
1

Just the other way, box in 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}

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.