Published 2010-03-18 |
Author:
Uwe Ziegenhagen

This is an expanded version of an example provided by T. Tantau

Do you have a question regarding this example, TikZ or LaTeX in general? Just ask in the
**LaTeX Forum**.

Oder frag auf Deutsch auf TeXwelt.de.
En français: TeXnique.fr.

```
\documentclass{article}
% Set operations illustrated with Venn diagrams
% Author: Uwe Ziegenhagen
% This is an expanded version of an example provided by T. Tantau
\usepackage{tikz}
\begin{document}
% Definition of circles
\def\firstcircle{(0,0) circle (1.5cm)}
\def\secondcircle{(0:2cm) circle (1.5cm)}
\colorlet{circle edge}{blue!50}
\colorlet{circle area}{blue!20}
\tikzset{filled/.style={fill=circle area, draw=circle edge, thick},
outline/.style={draw=circle edge, thick}}
\setlength{\parskip}{5mm}
% Set A and B
\begin{tikzpicture}
\begin{scope}
\clip \firstcircle;
\fill[filled] \secondcircle;
\end{scope}
\draw[outline] \firstcircle node {$A$};
\draw[outline] \secondcircle node {$B$};
\node[anchor=south] at (current bounding box.north) {$A \cap B$};
\end{tikzpicture}
%Set A or B but not (A and B) also known a A xor B
\begin{tikzpicture}
\draw[filled, even odd rule] \firstcircle node {$A$}
\secondcircle node{$B$};
\node[anchor=south] at (current bounding box.north) {$\overline{A \cap B}$};
\end{tikzpicture}
% Set A or B
\begin{tikzpicture}
\draw[filled] \firstcircle node {$A$}
\secondcircle node {$B$};
\node[anchor=south] at (current bounding box.north) {$A \cup B$};
\end{tikzpicture}
% Set A but not B
\begin{tikzpicture}
\begin{scope}
\clip \firstcircle;
\draw[filled, even odd rule] \firstcircle node {$A$}
\secondcircle;
\end{scope}
\draw[outline] \firstcircle
\secondcircle node {$B$};
\node[anchor=south] at (current bounding box.north) {$A - B$};
\end{tikzpicture}
% Set B but not A
\begin{tikzpicture}
\begin{scope}
\clip \secondcircle;
\draw[filled, even odd rule] \firstcircle
\secondcircle node {$B$};
\end{scope}
\draw[outline] \firstcircle node {$A$}
\secondcircle;
\node[anchor=south] at (current bounding box.north) {$B - A$};
\end{tikzpicture}
\end{document}
```

## Comments

Thank you, very useful example.

Many thanks for such a useful example :-)

Great examples for clipping! Thanks!

How can I draw a rectangle arround the circles?

would please,. what or how should it done?

Adding comments is currently not enabled.