16

Yesterday I came across this question: How to draw Venn diagrams (especially: complements) in LaTeX. I was introduced to the idea of intersecting circles and only filling in specific sections defined by the boundaries of the lines of the intersecting circles. Some examples are given in the above link but I began experimenting myself and was able to generate a large number of patterns:

enter image description here

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[fill=blue]
    %\draw[gray!30] (-2,-2) grid (2,2) (0,0);
    \begin{scope}
    \clip (330:0.75) circle (1);
    \fill (210:0.75) circle (1);
    \fill (90:0.75) circle (1);
    \end{scope}
    \begin{scope}
    \clip (330:0.75) circle (1) (210:0.75) circle (1);
    \fill (90:0.75) circle (1);
    \end{scope}
    \draw[color=black] (210:0.75) circle (1) node[]{A}; 
    \draw[color=black] (330:0.75) circle (1) node[]{B}; 
    \draw[color=black] (90:0.75) circle (1) node[]{C};
    
    \begin{scope}[xshift=3.5cm]
    \clip (330:0.75) circle (1) (210:0.75) circle (1);
    \fill (90:0.75) circle (1);
    \end{scope}
    \draw[color=black,xshift=3.5cm] (210:0.75) circle (1) node[]{A}; 
    \draw[color=black,xshift=3.5cm] (330:0.75) circle (1) node[]{B}; 
    \draw[color=black,xshift=3.5cm] (90:0.75) circle (1) node[]{C};
    
    \begin{scope}[xshift=7cm]
    \clip (90:0.75) circle (1) (210:0.75) circle (1);
    \fill (330:0.75) circle (1);
    \end{scope}
    \draw[color=black,xshift=7cm] (210:0.75) circle (1) node[]{A}; 
    \draw[color=black,xshift=7cm] (330:0.75) circle (1) node[]{B}; 
    \draw[color=black,xshift=7cm] (90:0.75) circle (1) node[]{C};
    
    \begin{scope}[xshift=10.5cm]
    \clip (90:0.75) circle (1) (330:0.75) circle (1);
    \fill (210:0.75) circle (1);
    \end{scope}
    \draw[color=black,xshift=10.5cm] (210:0.75) circle (1) node[]{A}; 
    \draw[color=black,xshift=10.5cm] (330:0.75) circle (1) node[]{B}; 
    \draw[color=black,xshift=10.5cm] (90:0.75) circle (1) node[]{C};
    
    \begin{scope}[even odd rule,yshift=-3.5cm]
    \clip (90:0.75) circle (1) (330:0.75) circle (1);
    \fill (210:0.75) circle (1);
    \end{scope}
    \draw[color=black,yshift=-3.5cm] (210:0.75) circle (1) node[]{A}; 
    \draw[color=black,yshift=-3.5cm] (330:0.75) circle (1) node[]{B}; 
    \draw[color=black,yshift=-3.5cm] (90:0.75) circle (1) node[]{C};
    
    \begin{scope}[even odd rule,yshift=-3.5cm, xshift=3.5cm]
    \clip (330:0.75) circle (1) (210:0.75) circle (1);
    \fill (90:0.75) circle (1);
    \end{scope}
    \draw[color=black,yshift=-3.5cm,xshift=3.5cm] (210:0.75) circle (1) node[]{A}; 
    \draw[color=black,yshift=-3.5cm,xshift=3.5cm] (330:0.75) circle (1) node[]{B}; 
    \draw[color=black,yshift=-3.5cm,xshift=3.5cm] (90:0.75) circle (1) node[]{C};
    
    \begin{scope}[even odd rule,yshift=-3.5cm, xshift=7cm]
    \clip (210:0.75) circle (1) (90:0.75) circle (1);
    \fill (330:0.75) circle (1);
    \end{scope}
    \draw[color=black,yshift=-3.5cm,xshift=7cm] (210:0.75) circle (1) node[]{A}; 
    \draw[color=black,yshift=-3.5cm,xshift=7cm] (330:0.75) circle (1) node[]{B}; 
    \draw[color=black,yshift=-3.5cm,xshift=7cm] (90:0.75) circle (1) node[]{C};
    
    %other ideas: clipping 2 circles and filling 2. that fills the non-intersected region of one circle, and only the intersection of the other two circles.
    
    \begin{scope}[even odd rule,yshift=-3.5cm, xshift=10.5cm]
    \clip (210:0.75) circle (1);
    \fill (330:0.75) circle (1) (90:0.75) circle (1);
    \end{scope}
    \begin{scope}[even odd rule,yshift=-3.5cm, xshift=10.5cm]
    \clip (330:0.75) circle (1);
    \fill (210:0.75) circle (1)  (90:0.75) circle (1);
    \end{scope}
    \begin{scope}[even odd rule,yshift=-3.5cm, xshift=10.5cm]
    \clip (90:0.75) circle (1);
    \fill (330:0.75) circle (1) (210:0.75) circle (1);
    \end{scope}
    \draw[color=black,yshift=-3.5cm,xshift=10.5cm] (210:0.75) circle (1) node[]{A}; 
    \draw[color=black,yshift=-3.5cm,xshift=10.5cm] (330:0.75) circle (1) node[]{B}; 
    \draw[color=black,yshift=-3.5cm,xshift=10.5cm] (90:0.75) circle (1) node[]{C};
    
    \begin{scope}[even odd rule,yshift=-7cm]
    \clip (210:0.75) circle (1);
    \fill (330:0.75) circle (1) (90:0.75) circle (1) (210:0.75) circle (1);
    \end{scope}
    \draw[color=black,yshift=-7cm] (210:0.75) circle (1) node[]{A}; 
    \draw[color=black,yshift=-7cm] (330:0.75) circle (1) node[]{B}; 
    \draw[color=black,yshift=-7cm] (90:0.75) circle (1) node[]{C};
    
    \begin{scope}[even odd rule,yshift=-7cm, xshift=3.5cm]
    \clip (210:0.75) circle (1) (90:0.75) circle (1);
    \fill (330:0.75) circle (1) (210:0.75) circle (1);
    \end{scope}
    \draw[color=black,yshift=-7cm, xshift=3.5cm] (210:0.75) circle (1) node[]{A}; 
    \draw[color=black,yshift=-7cm, xshift=3.5cm] (330:0.75) circle (1) node[]{B}; 
    \draw[color=black,yshift=-7cm, xshift=3.5cm] (90:0.75) circle (1) node[]{C};
    
    \begin{scope}[even odd rule,yshift=-7cm, xshift=7cm,fill=purple]
    \clip (210:0.75) circle (1) (90:0.75) circle (1) (330:0.75) circle (1);
    \fill[red] (90:0.75) circle (1) (330:0.75) circle (1) (210:0.75) circle (1) (210:1);
    \end{scope}
    \draw[color=black,yshift=-7cm, xshift=7cm] (210:0.75) circle (1) node[]{A}; 
    \draw[color=black,yshift=-7cm, xshift=7cm] (330:0.75) circle (1) node[]{B}; 
    \draw[color=black,yshift=-7cm, xshift=7cm] (90:0.75) circle (1) node[]{C};
    
    \begin{scope}[nonzero rule,yshift=-7cm, xshift=10.5cm]
    \clip (210:0.75) circle (1) (90:0.75) circle (1);
    \fill (330:0.75) circle (1) (210:0.75) circle (1);
    \end{scope}
    \draw[color=black,yshift=-7cm, xshift=10.5cm] (210:0.75) circle (1) node[]{A}; 
    \draw[color=black,yshift=-7cm, xshift=10.5cm] (330:0.75) circle (1) node[]{B}; 
    \draw[color=black,yshift=-7cm, xshift=10.5cm] (90:0.75) circle (1) node[]{C};
\end{tikzpicture}

\begin{tikzpicture}[opacity=0.5]
    \draw[color=black, fill=red] (210:0.75) circle (1) node[]{A}; 
    \draw[color=black,fill=green] (330:0.75) circle (1) node[]{B}; 
    \draw[color=black,fill=blue] (90:0.75) circle (1) node[]{C};
    
    \draw[color=black, fill=gray!10,xshift=3.5cm] (210:0.75) circle (1) node[]{A}; 
    \draw[color=black,fill=gray!10,xshift=3.5cm] (330:0.75) circle (1) node[]{B}; 
    \draw[color=black,fill=gray!10,xshift=3.5cm] (90:0.75) circle (1) node[]{C};
\end{tikzpicture}

\end{document}

The one pattern I haven't been able to figure out how to make is having only the intersection of the three circles filled. (Or the reverse: having only the intersected region of the three circles unfilled.) How can this be done? And if it can be done, can it be done with the general pattern of code I was producing myself (i.e. just some scope, possibly some use of the even odd rule) but in a way I haven't figured out yet?

EDIT: OK, so I figured out one way to do it (and independently @Steven B. Segletes came up with the same idea below), and that was just to make some white-filled shapes and put them over the blue regions in the right place so that only the blue in the middle would show. Here's what I got:

enter image description here

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[,fill=blue]
    \begin{scope}[even odd rule,yshift=-7cm]
    \clip (210:0.75) circle (1);
    \fill (330:0.75) circle (1) (90:0.75) circle (1) (210:0.75) circle (1);
    \end{scope}
    \draw[yshift=-6.6cm,xshift=-26,rotate=45,fill=white,color=white] (-1.5,-2) rectangle (-0,0.5);
    \draw[yshift=-5cm,xshift=-39,rotate=45,fill=white,color=white] (-1.5,-2) rectangle (-0,0.5);
    \draw[color=black,yshift=-7cm] (210:0.75) circle (1) node[]{A}; 
    \draw[color=black,yshift=-7cm] (330:0.75) circle (1) node[]{B}; 
    \draw[color=black,yshift=-7cm] (90:0.75) circle (1) node[]{C};
\end{tikzpicture}

\end{document}

Still, this method seems inefficient (took me a few minutes to position those rectangles in just the right place) and takes away from the use of mathematical precision (as opposed to the manual positioning and colouring I could do on, say, Photoshop or LucidChart) that I like about using something like Tikz. Is there a better way to do this?

1
  • Not sure I'm clear on what you're missing, but isn't the very centre done by clipping against all three circles without using the even odd rule? Apr 14, 2022 at 18:23

4 Answers 4

14

By not using the even odd rule then clips accumulate within a scope. They do need to be distinct paths, though, for this to happen. Otherwise it treats it as a single path and clips against the outside of it.

\documentclass{article}
%\url{https://tex.stackexchange.com/q/640808/86}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
% Store the centres in coordinates for ease of use
\coordinate (A) at (210:0.75);
\coordinate (B) at (330:0.75);
\coordinate (C) at (90:0.75);
\begin{scope}
% Could use a `\foreach` loop here, as below
\clip (A) circle[radius=1]; 
\clip (B) circle[radius=1];
\clip (C) circle[radius=1];
% Could use any of the circles here
\fill[blue] (A) circle[radius=1]; 
\end{scope}
\foreach \coord in {A,B,C}
{
  \draw (\coord) circle[radius=1];
  \node at (\coord) {\(\coord\)};
}
\end{tikzpicture}
\end{document}

Incidentally, modern Tikz syntax is circle[radius=1].

Venn diagram with the centre highlighted

1
  • Yes it does work, well done! I could've sworn though that I tried every combination. When you get on a laptop, do you mind editing this answer to include the image? (Just for completeness of the answer so I can check mark it for future reference as other people may look for this.)
    – arara
    Apr 14, 2022 at 18:39
13

I know that simply you can use venndiagram package to obtain the desidered output. See the manual and you can built all your drawings.

\documentclass[a4paper,12pt]{article}
\usepackage{tikz,venndiagram}

\begin{document}

\begin{venndiagram3sets}
\fillACapBCapC
\end{venndiagram3sets}
\end{document}

enter image description here

2
  • 4
    "There's a package for that" ... I'm pleased someone posted a solution using the venndiagram package. Whether or not it's what the OP wanted, it's important to remember that the questions and answers are for others as well who might be saved a lot of time and effort by knowing that this package exists! Apr 14, 2022 at 21:13
  • @AndrewStacey Kindest. Unfortunately, I have been helping myself to 5+ years of membership with drawings and pictures and I don't understand most of the time what the OP is asking for. I thank you for your message and as soon as I have seen the drawing I have thought to venndiagram package.
    – Sebastiano
    Apr 15, 2022 at 14:13
11

Pstricks has a dedicated package – pst-venn – which uses a very shortcode. Each of the parts defined by three intersecting circles has a number (from 1 to 7 since there are seven parts) and the intersection of all circles has number 7, so we have this code:

    \documentclass[border=6pt, pstricks, svgnames]{standalone}
    \usepackage{pst-venn}

    \begin{document}

    \begin{pspicture*}(-10,-6 )(10,12)
    \psVenn[bgcircle=false,fgcolor=Thistle](-1,0.5)(0,-1)(1,0.5){1.5}{7}
    \end{pspicture*}

    \end{document} 

enter image description here

9

I'm sure there is a better way, but I just superimposed several of your fills (namely your 1st and 8th figures), changing colors as I went.

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
    %\draw[gray!30] (-2,-2) grid (2,2) (0,0);
    \begin{scope}
    \clip (330:0.75) circle (1);
    \fill[red] (210:0.75) circle (1);
    \fill[red] (90:0.75) circle (1);
    \end{scope}
    \begin{scope}
    \clip (330:0.75) circle (1) (210:0.75) circle (1);
    \fill[red] (90:0.75) circle (1);
    \end{scope}
    \begin{scope}[even odd rule]
    \clip (210:0.75) circle (1);
    \fill[white] (330:0.75) circle (1) (90:0.75) circle (1);
    \end{scope}
    \begin{scope}[even odd rule]
    \clip (330:0.75) circle (1);
    \fill[white] (210:0.75) circle (1)  (90:0.75) circle (1);
    \end{scope}
    \begin{scope}[even odd rule]
    \clip (90:0.75) circle (1);
    \fill[white] (330:0.75) circle (1) (210:0.75) circle (1);
    \end{scope}
    \draw[color=black] (210:0.75) circle (1) node[]{A}; 
    \draw[color=black] (330:0.75) circle (1) node[]{B}; 
    \draw[color=black] (90:0.75) circle (1) node[]{C};
\end{tikzpicture}

\end{document}

enter image description here

4
  • Can't you just clip against all three circles without using the even odd rule? Apr 14, 2022 at 18:24
  • I actually also just came up and implemented this superimposing method myself, although with a simpler code. I added it to an edit, but yeah, I'm looking for a more efficient way of achieving this (per my edit above).
    – arara
    Apr 14, 2022 at 18:25
  • 1
    @AndrewStacey When it comes to tikz, I'm literally a monkey typing at a typewriter. That it clipped at all is testament to the adage, "even a broken clock is right twice a day". I only answered because, at that time, no one else had. Apr 14, 2022 at 18:54
  • 2
    @StevenB.Segletes Oh, absolutely! I've lost track of the number of times I've written a hacky solution just to get something there, only for someone to post something elegant ... but several days later. Apr 14, 2022 at 19:02

You must log in to answer this question.

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