How to draw a Venn diagram in TikZ?
I would suggest some modifications: instead of crowding the diagram with information, you can use colors and a legend to display some of the information; in my example code I used a simple tabular to build the legend; also notice that no additional libraries were used
\documentclass{article}
\usepackage{array}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\def\radius{2cm}
\def\mycolorbox#1{\textcolor{#1}{\rule{2ex}{2ex}}}
\colorlet{colori}{blue!70}
\colorlet{colorii}{red!70}
\coordinate (ceni);
\coordinate[xshift=\radius] (cenii);
\draw[fill=colori,fill opacity=0.5] (ceni) circle (\radius);
\draw[fill=colorii,fill opacity=0.5] (cenii) circle (\radius);
\draw ([xshift=-20pt,yshift=20pt]current bounding box.north west)
rectangle ([xshift=20pt,yshift=-20pt]current bounding box.south east);
\node[yshift=10pt] at (current bounding box.north) {Number of total episodes of case};
\node at ([xshift=\radius]current bounding box.east)
{
\begin{tabular}{@{}lr@{\,=\,}c@{}}
& Total & 431 \\
\mycolorbox{colori!50} & Env. & 189 \\
\mycolorbox{colorii!50} & Pat. & 422 \\
\end{tabular}
};
\node[xshift=-.5\radius] at (ceni) {$9$};
\node[xshift=.5\radius] at (cenii) {$242$};
\node[xshift=.9\radius] at (ceni) {$180$};
\node[xshift=10pt,yshift=10pt] at (current bounding box.south west) {$\emptyset$};
\end{tikzpicture}
\end{document}
After a comment, here's another variant:
\documentclass{article}
\usepackage{array}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\def\radius{2cm}
\def\mycolorbox#1{\textcolor{#1}{\rule{2ex}{2ex}}}
\colorlet{colori}{blue!70}
\colorlet{colorii}{red!70}
% some coordinates for the center of the circles
\coordinate (ceni);
\coordinate[xshift=\radius] (cenii);
% the circles
\draw (ceni) circle (\radius);
\draw (cenii) circle (\radius);
% the rectangle
\draw ([xshift=-25pt,yshift=25pt]current bounding box.north west)
rectangle ([xshift=25pt,yshift=-25pt]current bounding box.south east);
%the labels
\node[xshift=-.5\radius] at (ceni) {$9$};
\node[xshift=.5\radius] at (cenii) {$242$};
\node[xshift=.9\radius] at (ceni) {$180$};
\node[xshift=-30pt,yshift=\radius+10pt] at (ceni) {Pat.${}=180$};
\node[xshift=30pt,yshift=\radius+10pt] at (cenii) {Env.${}=422$};
\node[xshift=10pt,yshift=10pt] at (current bounding box.south west) {$\emptyset$};
\node[yshift=10pt] at (current bounding box.north) {Number of total episodes of case};
\end{tikzpicture}
\end{document}
\documentclass[pstricks,border=12pt]{standalone}
\begin{document}
\begin{pspicture}(8,6)
\psframe(8,6)
\psset{fillstyle=solid,linecolor=cyan}
\pscircle[fillcolor=cyan!50](5.25,3){2}
\pscircle[fillcolor=white](2.75,3){2}
\pscircle[fillstyle=none](5.25,3){2}
\uput{5pt}[45](0,0){$\emptyset$}
\rput[r](2.75,3){Pat=9}
\rput[l](5.25,3){Env=242}
\rput[b](4,5){$B-A$}
\uput{2pt}[45](8,6){$H$}
\end{pspicture}
\end{document}
I will go about it differently. Instead, I will draw the circle as nodes. Then, with the fit
library, draw the borders. This way, you can write the labels relative to the named nodes.
The Code
%https://tex.stackexchange.com/questions/101839/tikz-venn-diagramm
\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{positioning,fit,calc}
\begin{document}
\begin{tikzpicture}
\colorlet{circle edge}{blue!50}
\colorlet{circle area}{blue!20}
\tikzset{
filled/.style={fill=circle area, thick,inner sep=0pt},
outline/.style={draw=circle edge, thick,inner sep=0pt}}
% The circles
\node (secondcircle) [circle,filled,text width=3cm] {};
\node (firstcircle) [circle,left=-1cm of secondcircle,outline,text width=3cm, fill=white] {};
\draw [outline] (secondcircle) circle (1.5cm);
% The labels
\node at ([xshift=-0.15cm]firstcircle) {$\mathrm{Pat=9}$};
\node at ([xshift=0.4cm]secondcircle) {$\mathrm{Env.=242}$};
\node at ($(firstcircle)!0.5!(secondcircle)$) {180};
% The rectangle and labels
\node (box) [fit=(firstcircle)(secondcircle), inner sep=1cm,draw,rounded corners] {};
\node at (box.north) [anchor=north] {$B-A$};
\node at (box.south west) [anchor=south west] {$\emptyset$};
\node at (box.south) [anchor=north] {432 total};
\node at (box.north east) [anchor=south west] {$H$};
\end{tikzpicture}
\end{document}
The Output
BTW, if you have a lot of Venn Diagrams of two or three sets to draw, I advise you to try the package venndiagram
by Nicola Talbot.
Update
I was not so sure at first what should be placed where, but the code below seems to be a more complete attempt.
\documentclass[tikz,border=5,convert={density=150}]{standalone}
\usetikzlibrary{positioning,fit,calc}
\begin{document}
\begin{tikzpicture}
\colorlet{circle edge}{blue!50}
\colorlet{circle area}{blue!20}
\tikzset{filled/.style={fill=circle area, thick,inner sep=0pt}, outline/.style={draw=circle edge, thick,inner sep=0pt}}
% The circles
\node (secondcircle) [circle,filled,text width=3cm] {};
\node (firstcircle) [circle,left=-1cm of secondcircle,outline,text width=3cm, fill=white] {};
\draw [outline] (secondcircle) circle (1.5cm);
% The labels
\node at ([xshift=-0.8cm]firstcircle.north) [anchor=south] {$\mathrm{Pat=422}$};
\node at ([xshift=0.8cm]secondcircle.north) [anchor=south] {$\mathrm{Env.=189}$};
\node at ($(firstcircle)!0.5!(secondcircle)$) {180};
\node at (firstcircle) {9};
\node at (secondcircle) {242};
% The rectangle and labels
\node (box) [fit=(firstcircle)(secondcircle), inner sep=1cm,draw, ultra thick,rounded corners] {};
\node [below=12pt of box.north] {$B-A$};
\node at (box.south west) [anchor=south west] {$\emptyset$};
\node at (box.south) [anchor=north] {431 total};
\node at (box.north east) [anchor=south west] {$H$};
\end{tikzpicture}
\end{document}
The coordinates with respect to the named nodes are called anchors
. center
is the only anchor present in all shapes. So if you name an anchor as A
, then you can position another object, say, at A.center
. Some more anchors are north
, south
, east
, west
, etc. You can see more of these in the pgfmanual
. Just type and enter texdoc pgf
in your terminal. In version 2.10, you can see some explanations starting from Section 16.5 on Positioning Nodes.