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 9452 times

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

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

Here is my code
  1. \documentclass{article}
  2.  
  3. \usepackage{tikz}
  4. %\usetikzlibrary{shapes,backgrounds}
  5.  
  6. \begin{document}
  7. \pagestyle{empty}
  8.  
  9. \def\firstcircle{(0,0) circle (1.5cm)}
  10. \def\secondcircle{(55:2cm) circle (1.5cm)}
  11. \def\thirdcircle{(0:2cm) circle (1.5cm)}
  12.  
  13. \begin{tikzpicture}[line width=0.25pt]
  14.  
  15. \begin{scope}
  16. \fill[red] \secondcircle;
  17. \fill[green] \firstcircle;
  18. \fill[blue] \thirdcircle;
  19. \end{scope}
  20.  
  21. \begin{scope}
  22. \clip \firstcircle;
  23. \fill [yellow]
  24. \secondcircle;
  25. \end{scope}
  26.  
  27. \begin{scope}
  28. \clip \secondcircle;
  29. \fill [magenta] \thirdcircle;
  30. \end{scope}
  31.  
  32. \begin{scope}
  33. \clip \firstcircle;
  34. \fill [cyan] \thirdcircle;
  35. \end{scope}
  36.  
  37. \begin{scope}
  38. \clip \firstcircle;
  39. \clip \secondcircle;
  40. \fill [white] \thirdcircle;
  41. \end{scope}
  42.  
  43.  
  44. \draw \firstcircle node[text=white, below] {$B$};
  45. \draw \secondcircle node [text=white,above] {$A$};
  46. \draw \thirdcircle node [text=white,below] {$C$};
  47.  
  48. \end{tikzpicture}
  49.  
  50. \end{document}

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
localghost
Site Moderator
Posts: 9206
Joined: Fri Feb 02, 2007 12:06 pm
Location: Braunschweig, Germany

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.
  1. \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 13.1 (Linux 3.11.10), TeX Live 2013 (vanilla), TeXworks 0.5 (r1351)
² Posting stopped indefinitely due to offenses

Link:
BBcode:
HTML:
Hide post links
Show post links

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

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.

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
localghost
Site Moderator
Posts: 9206
Joined: Fri Feb 02, 2007 12:06 pm
Location: Braunschweig, Germany

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.
  1. \documentclass{article}
  2. \usepackage{tikz}
  3. %\usetikzlibrary{shapes,backgrounds}
  4.  
  5. \pagestyle{empty}
  6.  
  7. \def\firstcircle{(90:1.75cm) circle (2.5cm)}
  8. \def\secondcircle{(210:1.75cm) circle (2.5cm)}
  9. \def\thirdcircle{(330:1.75cm) circle (2.5cm)}
  10.  
  11. \begin{document}
  12. \begin{tikzpicture}
  13. \begin{scope}
  14. \fill[red]\firstcircle;
  15. \fill[green] \secondcircle;
  16. \fill[blue] \thirdcircle;
  17. \end{scope}
  18. \begin{scope}
  19. \clip \secondcircle;
  20. \fill[yellow] \firstcircle;
  21. \end{scope}
  22. \begin{scope}
  23. \clip \secondcircle;
  24. \fill[cyan] \thirdcircle;
  25. \end{scope}
  26. \begin{scope}
  27. \clip \firstcircle;
  28. \fill[magenta] \thirdcircle;
  29. \end{scope}
  30. \begin{scope}
  31. \clip \firstcircle;
  32. \clip \secondcircle;
  33. \fill[white] \thirdcircle;
  34. \end{scope}
  35. \draw \firstcircle node[text=white,above] {$A$};
  36. \draw \secondcircle node [text=white,below left] {$B$};
  37. \draw \thirdcircle node [text=white,below right] {$C$};
  38. \begin{scope}[font=\small]
  39. \node(0,0) {$A\cap B\cap C$};
  40. \draw(30:1.5cm) node {$A\cap C$};
  41. \draw(150:1.5cm) node {$A\cap B$};
  42. \draw(270:1.5cm) node {$B\cap C$};
  43. \end{scope}
  44. \end{tikzpicture}
  45. \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 13.1 (Linux 3.11.10), TeX Live 2013 (vanilla), TeXworks 0.5 (r1351)
² Posting stopped indefinitely due to offenses

Link:
BBcode:
HTML:
Hide post links
Show post links

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

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

Thank you very much. You helped a lot.

Link:
BBcode:
HTML:
Hide post links
Show post links


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: Bing [Bot] and 4 guests