# Positioning entries in a Venn diagram - edited version

The code here displays the numbers in a Venn diagram for three sets quite aesthetically. (The sets are A, B, and C, but f, F, g, G, h, and H are displayed; they are there just to facilitate reading the code. Three yellow line segments, three blue line segments, and three black line segments are displayed; they are there just to facilitate positioning of nodes.) I want to move some nodes a bit.

In the code, P is the name of the node at the center of the diagram; in the display, 2 is put at the location of P. How do I put A, B, and C at the end of the black line segments? (C should be outside circle C.) How do I put 7 and 8 at the midpoint of the yellow line segments? Why is 3 put at the midpoint of one of the yellow line segments?

\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes}

\begin{document}

\begin{tikzpicture}
\draw[overlay,name path=circle A] (-2,2) circle ({2*sqrt(2)});
\draw[overlay,name path=circle B] (2,2) circle ({2*sqrt(2)});
\draw[overlay,name path=circle C] (0,-2) circle ({2*sqrt(2)});

\fill[pink!80,fill opacity=0.5,draw=red] (45:{2*sqrt(2)}) circle ({2*sqrt(2)});
\fill[pink!80,fill opacity=0.5,draw=red] (135:{2*sqrt(2)}) circle ({2*sqrt(2)});
\fill[pink!80,fill opacity=0.5,draw=red] (-90:2) circle ({2*sqrt(2)});

%The following commands make the following labels: the intersection of circle A and
%circle B that is outside circle C is labeled F, the intersection of circle A and
%circle C that is outside circle B is labeled G, and the intersection of circle B and
%circle C that is outside circle A is labeled H; the intersection of circle A and
%circle B that is inside circle C is labeled f, the intersection of circle A and
%circle C that is inside circle B is labeled g, and the intersection of circle B and
%circle C that is inside circle A is labeled h.
\path[name intersections={of= circle A and circle B, by={F,f}}];
\path[name intersections={of= circle A and circle C, by={G,g}}];
\path[name intersections={of= circle B and circle C, by={h,H}}];
\coordinate[label={$F$}] (point F) at (F);
\coordinate[label={below:$f$}] (point f) at (f);
\coordinate[label={below left:$G$}] (point G) at (G);
\coordinate[label={$g$}] (point g) at (g);
\coordinate[label={below right:$H$}] (point H) at (H);
\coordinate[label={$h$}] (point h) at (h);

%These commands label the point in the middle of the Venn diagram "P." ("P" is not to be displayed.)
%Also, "2" is placed at the location of "P."
\path[line width=0.1pt,name path=Ff] (F) -- (f);
\path[line width=0.1pt,name path=Gg] (G) -- (g);
\path[name intersections={of= Ff and Gg, by=P}];
\node at (P) {2};

%These commands position "5," the number of elements that belong to set $A \cap B$ but not to C,
%"6" the number of elements that belong to set $B \cap C$ but not to A, and "4," the number of
%elements that belong to set $A \cap C$ but not to B.
\path[name path=P-to-H] (P) -- (H);
\path[name intersections={of= P-to-H and circle A, by=P-to-H-and-circle A}];
\path (P-to-H-and-circle A) -- node{6} (H);
\draw[yellow,line width=0.1pt] (P) -- (H);

\path[name path=P-to-G] (P) -- (G);
\path[name intersections={of= P-to-G and circle B, by=P-to-G-and-circle B}];
\path (P-to-G-and-circle B) -- node{4} (G);
\draw[yellow,line width=0.1pt] (P) -- (G);

\path[line width=0.1pt,name path=P-to-F] (P) -- (F);
\path[name intersections={of= P-to-F and circle C, by=P-to-F-and-circle C}];
\path (P-to-F-and-circle C) -- node{5} (F);
\draw[yellow,line width=0.1pt] (P) -- (F);

%These commands position "3," the number of elements that belong to set A but not to $B \cup C$,
%"7," the number of elements that belong to set B but not to $A \cup C$, and "8", the number of
%elements that belong to set C but not to $A \cup B$.
\path[name path=ray-P-h-circle A] (P) -- ($(P)!6cm!0:(h)$);
\path[name intersections={of= ray-P-h-circle A and circle A, by=P-h-circle A-point}];
\path (h) -- node{3} (P-h-circle A-point);
\draw[line width=0.1pt] (P) -- (P-h-circle A-point);

\path[name path=ray-P-g-circle B] (P) -- ($(P)!6cm!0:(g)$);
\path[name intersections={of= ray-P-g-circle B and circle B, by=P-g-circle B-point}];
\path (h) -- node{7} (P-g-circle B-point);
\draw[line width=0.1pt] (P) -- (P-g-circle B-point);

\path[name path=ray-P-f-circle C] (P) -- ($(P)!6cm!0:(f)$);
\path[name intersections={of= ray-P-f-circle C and circle C, by=P-f-circle C-point}];
\path (h) -- node{8} (P-f-circle C-point);
\draw[line width=0.1pt] (P) -- (P-f-circle C-point);

%These commands position the numbers indicating the number of elements in one set that are not
%in the other two sets.

%\path[name intersections={of= Ff and Gg, by=P}];
%\coordinate (T) at ($(F)!0.5!(G)$);
%\draw[line width=0.1pt] (F) -- (G);

%These commands label the sets.
\path[overlay,name path=node A,blue,line width=0.1pt] (P) -- (150:7);
\path[overlay,name path=node B,blue,line width=0.1pt] (P) -- (30:7);
\path[overlay,name path=node C,blue,line width=0.1pt] (P) -- (-90:7);
\path[name intersections={of= node A and circle A, by=alpha}];
\path[name intersections={of= node B and circle B, by=beta}];
\path[name intersections={of= node C and circle C, by=gamma}];
\draw[overlay,blue,line width=0.1pt] (P) -- (alpha);
\draw[overlay,blue,line width=0.1pt] (P) -- (beta);
\draw[overlay,blue,line width=0.1pt] (P) -- (gamma);
\coordinate[label={$A$}] (set A) at (alpha.150);
\coordinate[label={$B$}] (set B) at (beta.30);
\coordinate[label={$C$}] (set C) at (gamma.-90);

\end{tikzpicture}

\end{document}


• Why not \node[anchor=150+180] at (alpha) {$A$};? (alpha is a coordinate so its .150 anchor (any of its anchors) is just the coordinate again.) – Qrrbrbirlbel May 12 '15 at 21:50
• @Qrrbrbirlbel That does place A, B, and C properly. Why +180? – Adelyn May 12 '15 at 22:11
• Well, just to calculate the anchor of the node with the angles you provided. The label just adds another node at a parent node (or a parant coordinate). That has nothing to do with the at part of the parent. I advice to read section 17.10 (pp. 239ff) in the PGF manual. Also, the label/pin positioning is not very precise as it snaps to certain places. – Qrrbrbirlbel May 12 '15 at 22:26
• @Qrrbrbirlbel Thanks for providing the link. I have been looking at the manual. I have not seen a discussion of the anchor option in Chapter 17, section 10. The code that you provided for placing A typesets A exactly how I wanted. So, I would like to know about anchor. – Adelyn May 13 '15 at 0:20

How do I put A, B, and C at the end of the black line segments?

A possible solution would be to change the labels of A, B and C to

\coordinate[label={above left:$A$}] (set A) at (alpha.150);
\coordinate[label={above right:$B$}] (set B) at (beta.30);
\coordinate[label={below:$C$}] (set C) at (gamma.-90);


If this placement is not quite what you imagined, it is possible to be tuned with the xshift and yshift parameter (Example: \coordinate[label={above left:$A$}, xshift=2cm, yshift=2cm] (set A) at (alpha.150);).

How do I put 7 and 8 at the midpoint of the yellow line segments? Why is 3 put at the midpoint of one of the yellow line segments?

Upon adding the draw-option to your paths, it becomes quite obvious, that 7 and 8 won't be placed midpoint. Therefore your commands:

\path (h) -- node{3} (P-h-circle A-point);
\path (h) -- node{7} (P-g-circle B-point);
\path (h) -- node{8} (P-f-circle C-point);


should be changed to:

\path (h) -- node{3} (P-h-circle A-point);
\path (g) -- node{7} (P-g-circle B-point);
\path (f) -- node{8} (P-f-circle C-point);


\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes}

\begin{document}

\begin{tikzpicture}
\draw[overlay,name path=circle A] (-2,2) circle ({2*sqrt(2)});
\draw[overlay,name path=circle B] (2,2) circle ({2*sqrt(2)});
\draw[overlay,name path=circle C] (0,-2) circle ({2*sqrt(2)});

\fill[pink!80,fill opacity=0.5,draw=red] (45:{2*sqrt(2)}) circle ({2*sqrt(2)});
\fill[pink!80,fill opacity=0.5,draw=red] (135:{2*sqrt(2)}) circle ({2*sqrt(2)});
\fill[pink!80,fill opacity=0.5,draw=red] (-90:2) circle ({2*sqrt(2)});

%The following commands make the following labels: the intersection of circle A and
%circle B that is outside circle C is labeled F, the intersection of circle A and
%circle C that is outside circle B is labeled G, and the intersection of circle B and
%circle C that is outside circle A is labeled H; the intersection of circle A and
%circle B that is inside circle C is labeled f, the intersection of circle A and
%circle C that is inside circle B is labeled g, and the intersection of circle B and
%circle C that is inside circle A is labeled h.
\path[name intersections={of= circle A and circle B, by={F,f}}];
\path[name intersections={of= circle A and circle C, by={G,g}}];
\path[name intersections={of= circle B and circle C, by={h,H}}];
\coordinate[label={$F$}] (point F) at (F);
\coordinate[label={below:$f$}] (point f) at (f);
\coordinate[label={below left:$G$}] (point G) at (G);
\coordinate[label={$g$}] (point g) at (g);
\coordinate[label={below right:$H$}] (point H) at (H);
\coordinate[label={$h$}] (point h) at (h);

%These commands label the point in the middle of the Venn diagram "P." ("P" is not to be displayed.)
%Also, "2" is placed at the location of "P."
\path[line width=0.1pt,name path=Ff] (F) -- (f);
\path[line width=0.1pt,name path=Gg] (G) -- (g);
\path[name intersections={of= Ff and Gg, by=P}];
\node at (P) {2};

%These commands position "5," the number of elements that belong to set $A \cap B$ but not to C,
%"6" the number of elements that belong to set $B \cap C$ but not to A, and "4," the number of
%elements that belong to set $A \cap C$ but not to B.
\path[name path=P-to-H] (P) -- (H);
\path[name intersections={of= P-to-H and circle A, by=P-to-H-and-circle A}];
\path (P-to-H-and-circle A) -- node{6} (H);
\draw[yellow,line width=0.1pt] (P) -- (H);

\path[name path=P-to-G] (P) -- (G);
\path[name intersections={of= P-to-G and circle B, by=P-to-G-and-circle B}];
\path (P-to-G-and-circle B) -- node{4} (G);
\draw[yellow,line width=0.1pt] (P) -- (G);

\path[line width=0.1pt,name path=P-to-F] (P) -- (F);
\path[name intersections={of= P-to-F and circle C, by=P-to-F-and-circle C}];
\path (P-to-F-and-circle C) -- node{5} (F);
\draw[yellow,line width=0.1pt] (P) -- (F);

%These commands position "3," the number of elements that belong to set A but not to $B \cup C$,
%"7," the number of elements that belong to set B but not to $A \cup C$, and "8", the number of
%elements that belong to set C but not to $A \cup B$.
\path[name path=ray-P-h-circle A] (P) -- ($(P)!6cm!0:(h)$);
\path[name intersections={of= ray-P-h-circle A and circle A, by=P-h-circle A-point}];
\path (h) -- node{3} (P-h-circle A-point);
\draw[line width=0.1pt] (P) -- (P-h-circle A-point);

\path[name path=ray-P-g-circle B] (P) -- ($(P)!6cm!0:(g)$);
\path[name intersections={of= ray-P-g-circle B and circle B, by=P-g-circle B-point}];
\path (g) -- node{7} (P-g-circle B-point);
\draw[line width=0.1pt] (P) -- (P-g-circle B-point);

\path[name path=ray-P-f-circle C] (P) -- ($(P)!6cm!0:(f)$);
\path[name intersections={of= ray-P-f-circle C and circle C, by=P-f-circle C-point}];
\path (f) -- node{8} (P-f-circle C-point);
\draw[line width=0.1pt] (P) -- (P-f-circle C-point);

%These commands position the numbers indicating the number of elements in one set that are not
%in the other two sets.

%\path[name intersections={of= Ff and Gg, by=P}];
%\coordinate (T) at ($(F)!0.5!(G)$);
%\draw[line width=0.1pt] (F) -- (G);

%These commands label the sets.
\path[overlay,name path=node A,blue,line width=0.1pt] (P) -- (150:7);
\path[overlay,name path=node B,blue,line width=0.1pt] (P) -- (30:7);
\path[overlay,name path=node C,blue,line width=0.1pt] (P) -- (-90:7);
\path[name intersections={of= node A and circle A, by=alpha}];
\path[name intersections={of= node B and circle B, by=beta}];
\path[name intersections={of= node C and circle C, by=gamma}];
\draw[overlay,blue,line width=0.1pt] (P) -- (alpha);
\draw[overlay,blue,line width=0.1pt] (P) -- (beta);
\draw[overlay,blue,line width=0.1pt] (P) -- (gamma);
\coordinate[label={above left:$A$}] (set A) at (alpha.150);
\coordinate[label={above right:$B$}] (set B) at (beta.30);
\coordinate[label={below:$C$}] (set C) at (gamma.-90);

\end{tikzpicture}

\end{document}


And produces the following output: