2

I'm looking to create a Venn diagram with 5 parts to it, with each part being inside the other, similar to:

enter image description here

However I'm not entirely sure where to begin. I've done a little reading on the tikz package and Venn diagrams in general but the best I can make uses this:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
\foreach \X [count=\Y starting from 2] in {$\mathbb{N}$,$\mathbb{W}$,$\mathbb{Z}$,$\mathbb{Q}$,$\mathbb{R}$}
{\draw (-\Y,-\Y/2) circle ({1.5*\Y} and \Y);
\node at (1-2*\Y,-1.1*\Y) {\X}; }
\node[anchor=south]{};
\end{tikzpicture}

\end{document}

But this just does not give what I'm looking for. I'm currently getting an output like such:enter image description here

Any help to fix would be great!

5
  • Can you please add the missing lines, so the code compiles once copied? Also a screenshot of your current result would be helpful. Thank you
    – MS-SPO
    Commented Jul 20, 2023 at 14:35
  • 1
    @MS-SPO Ah sorry just edited now! Should be able to compile now and I've included what my current diagram looks like... Commented Jul 20, 2023 at 14:41
  • Welcome to TeX.SX! Would tex.stackexchange.com/q/678487/47927 ? (I currently can't find another answer of mine which would probably fit even better ...) Commented Jul 20, 2023 at 14:42
  • @JasperHabicht Thank you! I'm trying to use this code but not sure how to change the diagram to have an anchor to the left, make the shapes oval and increase the gaps at the left edge Commented Jul 20, 2023 at 14:50
  • 1
    Found it: tex.stackexchange.com/q/659704/47927 . This is, of course, pretty much what you currently get. Well, the code in both links are only meant as starting points. Commented Jul 20, 2023 at 14:51

2 Answers 2

5

If you want to stick to the solution with the \foreach loop, you need to change the x and y coordinates in a way that you get the desired result, for example like this (added a vertical correction to the nodes, so that all letters sit on the same baseline):

\documentclass[border=10pt]{standalone}
\usepackage{amsfonts}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\foreach \X [count=\Y starting from 2] in
    {$\mathbb{N}$,$\mathbb{W}$,$\mathbb{Z}$,$\mathbb{Q}$,$\mathbb{R}$} {
        \draw ({0.5*\Y},0) circle ({0.75*\Y} and {0.25*\Y});
        \node[anchor=base, yshift=-0.67ex] at ({1.25*\Y-0.75},0) {\X}; 
    }
\end{tikzpicture}
\end{document}

enter image description here


How could I forgot to add an l3draw variant of the code:

\documentclass[border=10pt]{standalone}
\usepackage{amsfonts}
\usepackage{l3draw}

\begin{document}
    \ExplSyntaxOn
    \draw_begin:
    \clist_set:Nn \l_tmpa_clist {
        $\mathbb{N}$ , $\mathbb{W}$ , $\mathbb{Z}$ , $\mathbb{Q}$ , $\mathbb{R}$
    }
    \int_step_inline:nn { \clist_count:N \l_tmpa_clist } {
        \draw_path_ellipse:nnn { (0.5cm * ( #1 + 1) ) , 0cm } { 0.75cm * ( #1 + 1) , 0cm } { 0cm , 0.25cm * ( #1 + 1) }
        \draw_path_use_clear:n { stroke }
        \hcoffin_set:Nn \l_tmpa_coffin { \clist_item:Nn \l_tmpa_clist {#1} }
        \draw_coffin_use:Nnnn \l_tmpa_coffin { H } { hc } { ( 1.25cm * ( #1 + 1) - 0.75cm ) , -0.67ex }
    }
    \draw_end:
    \ExplSyntaxOff
\end{document}
6
  • 1
    Thank you very much! This was extremely useful Commented Jul 20, 2023 at 15:01
  • Hi, what is W? :-) just a curiosity.
    – Sebastiano
    Commented Jul 21, 2023 at 12:07
  • @Sebastiano I have not the slightest idea. It was in the OP's original code. Maybe it is the set of ... weird numbers? (ℕ means probably natural numbers without 0, and 𝕎 with zero ...) Commented Jul 21, 2023 at 12:09
  • @JasperHabicht Thank you very much. I never have seen this notation.
    – Sebastiano
    Commented Jul 23, 2023 at 21:15
  • 2
    @Sebastiano As Jasper correctly guesses, sometimes N denotes the "natural" (counting) numbers (from 1) while W stands for the "whole" numbers (including 0).
    – campa
    Commented Mar 21 at 15:27
3

Here's one way to do it. Perhaps you need to start working from inside out ...

  • help-grid starts at (0,0), extends 2 cm right and up \draw[help lines] (0,0) grid (2,2);
  • each path performs two actions \draw ( 0,0) ellipse (2cm and 1cm) node at (1.7,0) {R};
  • first, draw an ellipse with the given x- and y-radii
  • second put some text via a node (kindly watch the missing \)
  • move to the left, reducing radii, and shifting the text node, too

result

\documentclass[10pt,border=3mm,tikz]{standalone}
\usepackage{tikz}

\begin{document}
 \begin{tikzpicture}
    \draw[help lines] (0,0) grid (2,2);
    \draw (  0,0) ellipse (2cm and 1cm)     node at (1.7,0) {R};
    \draw (-.2,0) ellipse (1.7cm and .9cm)  node at (1.3,0) {Q};
    \draw (-.4,0) ellipse (1.4cm and .8cm)  node at (.7,0) {Z};
 \end{tikzpicture}
\end{document}

P.S.: Just for the fun of it, approaching supersonic ...

fun

\documentclass[10pt,border=3mm,tikz]{standalone}
\usepackage{tikz}
\usepackage{fontawesome}

\begin{document}
 \begin{tikzpicture}
    \draw[help lines] (0,0) grid (2,2);
    \draw (  0,0) ellipse (2cm and 1cm)     node at (1.7,0) {R};
    \draw (-.2,0) ellipse (1.7cm and .9cm)  node at (1.3,0) {Q};
    \draw (-.4,0) ellipse (1.4cm and .8cm)  node at (.7,0) {Z};
    \node[rotate=180] at (-1.6,0) {\faFighterJet};
 \end{tikzpicture}
\end{document}
3
  • 1
    Haha! Love the addition. This was quite easy to understand and helped a lot thank you! Made some adjustments to the ellipse sizes too :) Commented Jul 20, 2023 at 15:02
  • Thank you :) Know your tools ...
    – MS-SPO
    Commented Jul 20, 2023 at 15:03
  • 1
    @DuncanChrystal Actually, the original loop does pretty much the same, but it calculates the coordinates automatically and ... well, wrap everything in a loop. Of course, loops are sometimes hard to graps at first sight. But if you go through it step by step, you will discover that it is not too complicated actually. Commented Jul 20, 2023 at 15:04

You must log in to answer this question.

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