LaTeX forum ⇒ Graphics, Figures & Tablesvenn diagram

Information and discussion about graphics, figures & tables in LaTeX documents.
mobearette
Posts: 5
Joined: Sat Oct 31, 2009 1:43 pm

venn diagram

Postby mobearette » Sat Oct 31, 2009 2:02 pm

Hello everyone.

I have some troubles with my LaTeX homework. I should draw a venn diagram looking like this
captureex.png
captureex.png (19.24 KiB) Viewed 19904 times

What I did so far looks like this
blan.png
blan.png (13.73 KiB) Viewed 19904 times

I suppose you see my problem; I don't know how to insert
$A \bigcap B
etc on the right place.
Any ideas?

Here is my code
\documentclass{article}

\usepackage{tikz}
%\usetikzlibrary{shapes,backgrounds}

\begin{document}
\pagestyle{empty}

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

\begin{tikzpicture}[line width=0.25pt]

\begin{scope}
\fill[red] \secondcircle;
\fill[green] \firstcircle;
\fill[blue] \thirdcircle;
\end{scope}

\begin{scope}
\clip \firstcircle;
\fill  [yellow]
\secondcircle;
\end{scope}

\begin{scope}
\clip \secondcircle;
\fill [magenta] \thirdcircle;
\end{scope}

\begin{scope}
\clip \firstcircle;
\fill [cyan] \thirdcircle;
\end{scope}

\begin{scope}
\clip \firstcircle;
\clip \secondcircle;
\fill [white] \thirdcircle;
\end{scope}


    \draw \firstcircle node[text=white, below] {$B$};
    \draw \secondcircle node [text=white,above] {$A$};
    \draw \thirdcircle node [text=white,below] {$C$};

\end{tikzpicture}

\end{document} 

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics
User avatar
localghost
Site Moderator
Posts: 9201
Joined: Fri Feb 02, 2007 12:06 pm

venn diagram

Postby localghost » Sat Oct 31, 2009 2:11 pm

Just place the text as a node like you did with A, B, and C. The pgf/tikZ manual explains that in detail.
\node(x,y){$A\cap B\cap C$}


Note: Please upload attachments to the forum server!


Best regards and welcome to the board
Thorsten¹
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

mobearette
Posts: 5
Joined: Sat Oct 31, 2009 1:43 pm

venn diagram

Postby mobearette » Sat Oct 31, 2009 2:21 pm

localghost wrote:Note: Please upload attachments to the forum server!


Sorry, I didn't know about this rule.

Thx for the quick anwser.

User avatar
localghost
Site Moderator
Posts: 9201
Joined: Fri Feb 02, 2007 12:06 pm

venn diagram

Postby localghost » Sat Oct 31, 2009 3:31 pm

mobearette wrote:Sorry, I didn't know about this rule. […]

See Board Rules.

My first reply wasn't thought out very well. So here's the detailed version. In principle you have a radial symmetric construction. Hence it is better to work with polar coordinates because placement of objects is simplified.
\documentclass{article}
\usepackage{tikz}
%\usetikzlibrary{shapes,backgrounds}

\pagestyle{empty}

\def\firstcircle{(90:1.75cm) circle (2.5cm)}
\def\secondcircle{(210:1.75cm) circle (2.5cm)}
\def\thirdcircle{(330:1.75cm) circle (2.5cm)}

\begin{document}
  \begin{tikzpicture}
    \begin{scope}
      \fill[red]\firstcircle;
      \fill[green] \secondcircle;
      \fill[blue] \thirdcircle;
    \end{scope}
    \begin{scope}
      \clip \secondcircle;
      \fill[yellow] \firstcircle;
    \end{scope}
    \begin{scope}
      \clip \secondcircle;
      \fill[cyan] \thirdcircle;
    \end{scope}
    \begin{scope}
      \clip \firstcircle;
      \fill[magenta] \thirdcircle;
    \end{scope}
    \begin{scope}
      \clip \firstcircle;
      \clip \secondcircle;
      \fill[white] \thirdcircle;
    \end{scope}
    \draw \firstcircle node[text=white,above] {$A$};
    \draw \secondcircle node [text=white,below left] {$B$};
    \draw \thirdcircle node [text=white,below right] {$C$};
    \begin{scope}[font=\small]
      \node(0,0) {$A\cap B\cap C$};
      \draw(30:1.5cm) node {$A\cap C$};
      \draw(150:1.5cm) node {$A\cap B$};
      \draw(270:1.5cm) node {$B\cap C$};
    \end{scope}
  \end{tikzpicture}
\end{document}

The last scope environment consists of all the text that you want to place in this diagram.
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

mobearette
Posts: 5
Joined: Sat Oct 31, 2009 1:43 pm

Re: venn diagram

Postby mobearette » Sat Oct 31, 2009 4:05 pm

Thank you very much. You helped a lot.


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 6 guests