TransWikia.com

Question about drawing a Venn diagram for a set complement

TeX - LaTeX Asked on February 12, 2021

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}
deffirstcircle{(0,0) circle (1.5cm)}
defsecondcircle{(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!

One Answer

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

begin{document}
begin{tikzpicture}
deffirstcircle{(0,0) circle (1.5cm)}
defsecondcircle{(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

Correct answer by Zarko on February 12, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP