30

I have a 3-circle venn diagram

\def\firstcircle{(0,0) circle (2cm)}
\def\secondcircle{(55:2.67cm) circle (2cm)}
\def\thirdcircle{(0:3cm) circle (2cm)}

% Now we can draw the sets:
\begin{tikzpicture}
    \draw \firstcircle node[below] {$A$};
    \draw \secondcircle node [above] {$B$};
    \draw \thirdcircle node [below] {$C$};
\end{tikzpicture}

How do I add text labels where the circles overlap?

5 Answers 5

46

A simple solution is

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
  \tikzset{venn circle/.style={draw,circle,minimum width=6cm,fill=#1,opacity=0.4}}

  \node [venn circle = red] (A) at (0,0) {$A$};
  \node [venn circle = blue] (B) at (60:4cm) {$B$};
  \node [venn circle = green] (C) at (0:4cm) {$C$};
  \node[left] at (barycentric cs:A=1/2,B=1/2 ) {$A \cap B$}; 
  \node[below] at (barycentric cs:A=1/2,C=1/2 ) {$A \cap C$};   
  \node[right] at (barycentric cs:B=1/2,C=1/2 ) {$B \cap C$};   
  \node[below] at (barycentric cs:A=1/3,B=1/3,C=1/3 ){$A \cap B \cap C$};
\end{tikzpicture}  
\end{document}

enter image description here

6
  • 4
    Very nice use of barycentric coordinates. You could even handle circles of different radii by using appropriate factors in the coordinate specification. Commented Aug 20, 2011 at 10:49
  • Yes you are right but I made this solution very quickly without flourish . There is a little problem with the names of the first circles and opacity. Commented Aug 20, 2011 at 11:32
  • 2
    It's important to note that you cannot use spacesin the barycentric coordinate specifications (like A = 1/2). This is noted in section 13.2.2 of the TikZ manual, but it wouldn't be obvious to someone adapting the code from this answer. Adding the spaces leads to an error.
    – Aaron
    Commented Mar 19, 2013 at 0:14
  • It would have been nice to have an option to control/scale the size of the circles.
    – Curious
    Commented Jul 7, 2021 at 17:05
  • If someone wants the consistent label format without A,B,C influenced by opacity, we can use text opacity=1.
    – An5Drama
    Commented Feb 4 at 9:02
14

enter image description here

\documentclass{article}
\usepackage{pst-node}   
\SpecialCoor

\usepackage[active,tightpage]{preview}
\PreviewBorder=0pt\relax
\PreviewEnvironment{pspicture}

\begin{document}

\begin{pspicture}(-3.25,-3.25)(3.25,3.25)
  \def\R{1}
  \def\RR{2}    
  \pnode(\R;30){A}\rput(\RR;30){$A$}
  \pnode(\R;150){B}\rput(\RR;150){$B$}
  \pnode(\R;270){C}\rput(\RR;270){$C$}
  \psset{opacity=0.4}
  \def\r{2}
  \pscircle*[linecolor=red](A){\r} 
  \pscircle*[linecolor=green](B){\r} 
  \pscircle*[linecolor=blue](C){\r}
  \def\d{1.5}
  \rput(\d;90){$A \cap B$}
  \rput(\d;210){$B \cap C$}
  \rput(\d;-30){$A \cap C$}  
  \rput(0,0){$A\cap B\cap C$}
\end{pspicture}

\end{document}
0
11

You could place the labels manually by using \node at (<x>,<y>) {$A \cap C$};, but you'd have to find the coordinates by trial and error.

A more "proper" way is using the intersections library. To use it, you name the paths you want to intersect using unique names (name path=<name>), in this case the circles.

Then you can find the intersections by issuing name intersections = {of=<firstpath> and <secondpath>} as an argument to a path or a draw command.

The intersections will be available as coordinate nodes with the naming scheme intersection-<number>. You can now define a path between two intersections, and place a node halfway between the intersections using node [pos=0.5] {<label>} in the path.

For labelling the central overlap, you could use the calc library to specify the average of the circle coordinates using ($0.33*(A)+0.33*(B)+0.33*(C)$):

venn diagrams label

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\usetikzlibrary{calc}


\begin{document}

\def\firstcircle{[name path=firstcircle] (0,0) circle (2cm)}
\def\secondcircle{[name path=secondcircle] (55:2.67cm) circle (2cm)}
\def\thirdcircle{[name path=thirdcircle] (0:3cm) circle (2cm)}

% Now we can draw the sets:
\begin{tikzpicture}
    \draw \firstcircle node[below,name=A] {$A$};
    \draw \secondcircle node [above,name=B] {$B$};
    \draw \thirdcircle node [below,name=C] {$C$};
    \path [ name intersections = {of = firstcircle and secondcircle } ] (intersection-1) -- (intersection-2) node [pos=0.5] {$A \cap B$};
    \path [ name intersections = {of = secondcircle and thirdcircle } ] (intersection-1) -- (intersection-2) node [pos=0.5] {$B \cap C$};
    \path [ name intersections = {of = firstcircle and thirdcircle } ] (intersection-1) -- (intersection-2) node [pos=0.5] {$A \cap C$};
    \node at ($0.33*(B)+0.33*(C)+0.33*(A)$) {$A \cap B \cap C$};
\end{tikzpicture}

\end{document}
3
  • thanks, how about where the three overlap?
    – yolo
    Commented Aug 19, 2011 at 12:19
  • If you're using the calc library to get the threefold overlap, you might as well do it for the others. The A interect B label can go at $0.5*(A) + 0.5*(B)$, etc. Commented Aug 19, 2011 at 15:52
  • Also, do you have a solution that would accommodate circles of different sizes? For instance, if you change the size of circle A to 3cm, the label for B is in B intersect C, and the label for B intersect C is in A intersect B intersect C. Commented Aug 19, 2011 at 15:54
8

Run it with XeLaTeX

\documentclass{article}
\usepackage{pst-node}    
\begin{document}

\begin{pspicture}(-2,-2)(5,4)
  \psnode(0,0){first}{A}\psnode(2.67;55){second}{B}\psnode(3,0){third}{C}
  \pscircle*[linecolor=red,opacity=0.4](first){2} 
  \pscircle*[linecolor=green,opacity=0.4](second){2} 
  \pscircle*[linecolor=blue,opacity=0.4](third){2}
  \ncline[linestyle=none]{first}{second}\ncput{$A \cap B$}
  \ncline[linestyle=none]{first}{third}\ncput{\rnode{AC}{$A \cap C$}}
  \ncline[linestyle=none]{second}{third}\ncput{$B \cap C$}
  \ncline[linestyle=none]{second}{AC}\ncput[npos=0.75]{$A\cap B\cap C$}
\end{pspicture}

\end{document}

enter image description here

2
  • thanks, how about where the three overlap?
    – yolo
    Commented Aug 19, 2011 at 12:19
  • see edited answer
    – user2478
    Commented Aug 19, 2011 at 12:25
6

For anyone looking for something simple, consider using the venndiagram package (which depends on TikZ):

\documentclass{article}
\usepackage{venndiagram}

\begin{document}

\begin{venndiagram3sets}[labelOnlyAB={$A \cap B$},
                         labelOnlyAC={$A \cap C$},
                         labelOnlyBC={$B \cap C$},
                         labelABC={$A \cap B \cap C$},
                         radius=3cm,
                         overlap=2.5cm]
\end{venndiagram3sets}

\end{document}

enter image description here

Extra notes:

  • I did have to manually play with the overlap and radius numbers to get a good fit for the text.

  • You can pass options to tikzpicture with the venndiagram3sets option tikzoptions.

  • Although you can change the color, I think you cannot set separate colors for separate sets.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .