Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Is it possible to make a 4-set venn diagram using the tikz packages, like the following one? I know it must be, but the only information I can find on the subject uses R as the language.

enter image description here

So, an update. I am now wondering how to best fill just the isolated fields, that is, the part only in A, the part only in B, etc. For now, I have just the part in D filled. Any suggestions? Code below:

\documentclass[12pt]{article}

\usepackage{tikz} \usetikzlibrary{positioning,shapes.geometric}

% For drawing
\def\firstellip{(1.6, 0) ellipse [x radius=3cm, y radius=1.5cm, rotate=50]}
\def\secondellip{(0.3, 1cm) ellipse [x radius=3cm, y radius=1.5cm,
rotate=50]} \def\thirdellip{(-1.6, 0) ellipse [x radius=3cm, y radius=1.5cm,
rotate=-50]} \def\fourthellip{(-0.3, 1cm) ellipse [x radius=3cm, y
radius=1.5cm, rotate=-50]} \def\bounding{(-5,-3) rectangle (5,4)}

\begin{document}

\begin{tikzpicture} \filldraw[fill=black, opacity=0.2] \bounding;

    \scope \fill[white] \fourthellip; \endscope \filldraw[fill=red,
    opacity=0.2] \fourthellip;

    %single colors
    \scope \fill[white] \secondellip; \fill[white] \thirdellip; \fill[white]
    \firstellip; \endscope

    \draw \firstellip node [label={[xshift=2.0cm, yshift=-0.9cm]$A$}] {};
    \draw \secondellip node [label={[xshift=2.2cm, yshift=2.1cm]$B$}] {};
    \draw \thirdellip node [label={[xshift=-2.0cm, yshift=-0.9cm]$C$}] {};
    \draw \fourthellip node [label={[xshift=-2.2cm, yshift=2.1cm]$D$}] {};
    \draw \bounding node [label=above left:$U$] {};

\end{tikzpicture}  \end{document}

And displays as follows, I'm trying to get red in the four "corners". Thanks so much:

enter image description here

share|improve this question
2  
Welcome to TeX.sx! Please add a minimal working example (MWE) that shows what you've done so far; you'll stand a greater chance of getting help. –  lockstep Feb 26 '13 at 19:24
1  
Yes ... it's possible ! and there are a lot of examples. In Google : tex.stackexchange Venn –  Alain Matthes Feb 26 '13 at 19:33
    
Useful References: How to generate all possible Venn diagrams (with the case below) efficiently? and How to draw Venn diagrams (especially: complements) in LaTeX. The real tricky part here might be how to individually shade each possible region as was done in the first linked question. –  Peter Grill Feb 26 '13 at 19:35
    
@PeterGrill I added the venn-diagrams tag to the linked questions. –  lockstep Feb 26 '13 at 19:41

2 Answers 2

up vote 1 down vote accepted

There are some Venn diagrams with multiple elements coloured in this example: http://www.texample.net/tikz/examples/venn-diagram/

I've taken the principles used there and created a version with all four "corners" filled, as requested (I used yellow to distinguish from the original code which had one corner coloured red).

Venn with corners coloured

\documentclass[12pt]{article}

\usepackage{tikz} \usetikzlibrary{positioning,shapes.geometric}

% For drawing
\def\firstellip{(1.6, 0) ellipse [x radius=3cm, y radius=1.5cm, rotate=50]}
\def\secondellip{(0.3, 1cm) ellipse [x radius=3cm, y radius=1.5cm,
rotate=50]} \def\thirdellip{(-1.6, 0) ellipse [x radius=3cm, y radius=1.5cm,
rotate=-50]} \def\fourthellip{(-0.3, 1cm) ellipse [x radius=3cm, y
radius=1.5cm, rotate=-50]} \def\bounding{(-5,-3) rectangle (5,4)}

\begin{document}

\begin{tikzpicture} \filldraw[fill=black, opacity=0.2] \bounding;

    \scope \fill[white] \fourthellip; \endscope \filldraw[fill=red,
    opacity=0.2] \fourthellip;

    %single colors
    \scope \fill[white] \secondellip; \fill[white] \thirdellip; \fill[white]
    \firstellip; \endscope

    \draw \firstellip node [label={[xshift=2.0cm, yshift=-0.9cm]$A$}] {};
    \draw \secondellip node [label={[xshift=2.2cm, yshift=2.1cm]$B$}] {};
    \draw \thirdellip node [label={[xshift=-2.0cm, yshift=-0.9cm]$C$}] {};
    \draw \fourthellip node [label={[xshift=-2.2cm, yshift=2.1cm]$D$}] {};
    \draw \bounding node [label=above left:$U$] {};

    \begin{scope}
        \begin{scope}[even odd rule]% first ellipse corner
            \clip \secondellip (-5,-5) rectangle (5,5);
            \clip \thirdellip (-5,-5) rectangle (5,5);
            \clip \fourthellip (-5,-5) rectangle (5,5);
        \fill[yellow] \firstellip;
        \end{scope}
    \end{scope}

    \begin{scope}
        \begin{scope}[even odd rule]% second ellipse corner
            \clip \firstellip (-5,-5) rectangle (5,5);
            \clip \thirdellip (-5,-5) rectangle (5,5);
            \clip \fourthellip (-5,-5) rectangle (5,5);
        \fill[yellow] \secondellip;
        \end{scope}
    \end{scope}

    \begin{scope}
        \begin{scope}[even odd rule]% third ellipse corner
            \clip \secondellip (-5,-5) rectangle (5,5);
            \clip \firstellip (-5,-5) rectangle (5,5);
            \clip \fourthellip (-5,-5) rectangle (5,5);
        \fill[yellow] \thirdellip;
        \end{scope}
    \end{scope}


\end{tikzpicture}  \end{document}

The trick is to add a large rectangle that encompasses everything and then use the even-odd filling rule - see the texample page for more details.

(Btw - I used http://writeLaTeX.com to test the code - the document can be found here: https://www.writelatex.com/77868dfxncz )

share|improve this answer
    
PS: I saved this version of the answer in the writeLaTeX document - it can always be restored by going to the "history" menu in the writeLaTeX editor and restoring the "Answer to TeX SX question" version. –  John Hammersley Feb 27 '13 at 1:40

Result

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes.geometric}
\begin{document}
\tikzset{
  set/.style ={ 
    ellipse, 
    minimum width=3.5cm, 
    minimum height=2cm,
    draw,
}}
\begin{tikzpicture}
\foreach \x/\y/\a in {.7/0/60,.3/1/60,-.7/0/-60,-.3/1/-60} 
  \node[set, rotate=\a] at (\x,\y) {};
\end{tikzpicture}
\end{document}
share|improve this answer
1  
Why transform shape ? I think you don't need this option. –  Alain Matthes Feb 26 '13 at 19:42
    
@AlainMatthes You are right, it is not needed. I somewhat remembered that without it the node shape wont be rotated, but I was wrong. –  JLDiaz Feb 26 '13 at 19:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.