Question:
I want to put a tikzpicture as a margin figure. I have a minimal version with the sidenotes package. However, it wouldn't work with the tikzpicture I want to have there.
Example with sidenotes package:

MWE with sidenotes package:
\documentclass{scrbook}
\usepackage{graphicx}
\usepackage{placeins}
\usepackage{sidenotes}
\usepackage{lipsum}
\begin{document}
\begin{marginfigure}%
\includegraphics[width=\marginparwidth]{example-image-a}
\end{marginfigure}
\lipsum[1]
\end{document}
Problem:
I want to insert a tikzpicture in the margin. It looks like this:

\begin{tikzpicture}
\def\firstcircle{(0,0) circle (1.5cm)}
\def\secondcircle{(0:0.5cm) circle (0.8cm)}
\colorlet{circle edge}{red!50}
\colorlet{circle area}{red!20}
\tikzset{filled/.style={fill=circle area, draw=circle edge, thick},
outline/.style={draw=circle edge, thick}}
\setlength{\parskip}{5mm}
\begin{scope}
\clip \firstcircle;
\fill[filled] \secondcircle;
\end{scope}
\draw[outline] \firstcircle node [xshift=-20pt] {$M_2$};
\draw[outline] \secondcircle node {$M_1$};
\node[anchor=south] at (current bounding box.north) {$M_1 \subsetneq M_2$};
\end{tikzpicture}
The problem is that the document wouldn't compile, but I don't know why. I did the following:
\begin{marginfigure}%
\begin{figure}
\begin{tikzpicture}
...
\end{tikzpicture}
\end{figure}
\end{marginfigure}
How can I solve this problem?

\begin{figure}and\end{figure}from within yourmarginfigureenvironment? – cmhughes Dec 07 '20 at 08:56