3

My knowledge of TikZ is very limited. I'm drawing Venn diagrams of this style in my document:

enter image description here

\begin{figure}[H]
    \centering
\begin{tikzpicture}
\def\firstcircle{(0,0) circle (1.5cm)}
\def\secondcircle{(0:2cm) circle (1.5cm)}

\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 {$M_1$}; \draw[outline] \secondcircle node {$M_2$}; \node[anchor=south] at (current bounding box.north) {$M_1 \cap M_2$}; \end{tikzpicture} \end{figure}

Now, I want to draw a set complement see this one on Wikipedia, so I need to draw a box around it and fill it with some colour. The operation should be on top of the picture (like in the previous diagram). Does anybody know how to do that in the same kind of general style like the first diagram?

Thank you!

NilsK
  • 543
  • 1
    There are quite a lot of questions about Venn diagrams here, see https://tex.stackexchange.com/search?q=venn , and there's a Venn diagram package, at https://ctan.org/pkg/venndiagram . For example, this question will generate every possible 3-set Venn diagram https://tex.stackexchange.com/q/67395/86 and there is a follow-up for 2-set ones. – Andrew Stacey Nov 29 '20 at 10:12

1 Answers1

3
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{backgrounds, fit}

\begin{document}
\begin{tikzpicture}
\def\firstcircle{(0,0) circle (1.5cm)}
\def\secondcircle{(0:2cm) circle (1.5cm)}

\colorlet{circle edge}{red!50}
\colorlet{circle area}{red!20}

\tikzset{
    filled/.style = {draw=circle edge, fill=#1!, thick},
   outline/.style = {draw=circle edge, thick},
         F/.style = {draw, inner sep=7mm, fit=(current bounding box),
                  node contents={}}
}
\draw[filled=white] \firstcircle node {$M_1$};
\draw[outline] \secondcircle node {$M_2$};
\scoped[on background layer]
 \node (a) [F, fill=circle area];  
\node[anchor=north] at (current bounding box.north) {A^c=M_1 \setminus M_2};
\end{tikzpicture}
\end{document}

enter image description here

Zarko
  • 296,517