Graphics, Figures & Tablesvenn diagram

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

venn diagram

Post by mobearette »

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 20740 times
What I did so far looks like this
blan.png
blan.png (13.73 KiB) Viewed 20740 times
I suppose you see my problem; I don't know how to insert

Code: Select all

$A \bigcap B
etc on the right place.
Any ideas?

Here is my code

Code: Select all

\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

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

venn diagram

Post by localghost »

Just place the text as a node like you did with A, B, and C. The pgf/tikZ manual explains that in detail.

Code: Select all

\node(x,y){$A\cap B\cap C$}
Note: Please upload attachments to the forum server!


Best regards and welcome to the board
Thorsten¹
mobearette
Posts: 5
Joined: Sat Oct 31, 2009 1:43 pm

venn diagram

Post by mobearette »

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: 9202
Joined: Fri Feb 02, 2007 12:06 pm

venn diagram

Post by localghost »

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.

Code: Select all

\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.
mobearette
Posts: 5
Joined: Sat Oct 31, 2009 1:43 pm

Re: venn diagram

Post by mobearette »

Thank you very much. You helped a lot.
Post Reply