3

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: enter image description here

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: enter image description here

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

NilsK
  • 543
  • 2
    What happens if you remove \begin{figure} and \end{figure} from within your marginfigure environment? – cmhughes Dec 07 '20 at 08:56
  • https://tex.stackexchange.com/questions/135286/using-marginfigure-command --- https://tex.stackexchange.com/questions/411084/horizontal-alignment-of-tikz-floats-in-tufte-margins – js bibra Dec 07 '20 at 08:58
  • @cmhughes Thank you, it worked... I tried it before but it didn't work, I must have done something else wrong back then. – NilsK Dec 07 '20 at 09:01
  • @NilsK great! perhaps you could self-answer your question with full details of how you fixed it, including a complete, minimal example :) – cmhughes Dec 07 '20 at 09:11

1 Answers1

2

Thanks to @cmhughes the question could be answered. The solution is to remove the figure environment. I provide the following MWE:

enter image description here

\documentclass{scrbook}
\usepackage{graphicx}
\usepackage{placeins}
\usepackage{sidenotes}

\usepackage{lipsum} \usepackage{tikz} \usetikzlibrary{matrix,shapes,backgrounds,fit} \usepackage{amssymb}

\begin{document}

\begin{marginfigure}% \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} \end{marginfigure} \lipsum[1]

\end{document}

NilsK
  • 543