-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVennDiagram_tikz.tex
68 lines (52 loc) · 2.23 KB
/
VennDiagram_tikz.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
\documentclass[tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,backgrounds}
\begin{document}
\pagestyle{empty}
% Suppose we have three circles or ellipses or whatever. Let us define
% commands for their paths since we will need them repeatedly in the
% following:
\def\firstcircle{(0,0) circle (1.5cm)}
\def\secondcircle{(45:2cm) circle (1.5cm)}
\def\thirdcircle{(0:2cm) circle (1.5cm)}
% Now we can draw the sets:
\begin{tikzpicture}
\draw \firstcircle node[below] {$A$};
\draw \secondcircle node [above] {$B$};
\draw \thirdcircle node [below] {$C$};
% Now we want to highlight the intersection of the first and the
% second circle:
\begin{scope}
\clip \firstcircle;
\fill[red] \secondcircle;
\end{scope}
% Next, we want the highlight the intersection of all three circles:
\begin{scope}
\clip \firstcircle;
\clip \secondcircle;
\fill[green] \thirdcircle;
\end{scope}
% The intersection trick works pretty well for intersections. If you need
% the set-theoretic difference between two sets, things are a little more
% complicated:
% Suppose we want to highlight the part of the first circle that is not
% also part of the second circle. For this, we need to clip against the
% "complement" of the second circle. The trick is to add a large rectangle
% that encompasses everything and then use the even-odd filling rule
% (see the manual again):
\begin{scope}[shift={(6cm,0cm)}]
\begin{scope}[even odd rule]% first circle without the second
\clip \secondcircle (-3,-3) rectangle (3,3);
\fill[yellow] \firstcircle;
\end{scope}
\draw \firstcircle node {$A$};
\draw \secondcircle node {$B$};
\end{scope}
% When using the above, you will notice that the border lines of the
% original circles are erased by the intersection parts. To solve this
% problem, either use a background layer (see the manual) or simply draw
% the border lines after everything else has been drawn.
\end{tikzpicture}
% Naturally, all of this could be bundled into nicer macros, but the above
% should give the idea.
\end{document}