0

I 'm trying to make a Venn diagram of number sets (reals, rational, integers, natural numbers). I want every set to have its title and its symbol.

I tried this code

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,snakes}
\usepackage{amsmath,amssymb}



\begin{document}


% Define box and box title style
\tikzstyle{vennbox} = [draw,ultra thick,align=left,draw=black, fill=white, very thick,  rounded corners=10, inner sep=10pt, inner ysep=20pt]
\tikzstyle{venntitle} =[fill=black, text=white]

\begin{tikzpicture}
\node [vennbox] (box){%
    $\sqrt{2}$ \ $0{,}1010010001\dots$ \ \ $\pi$ \\
    \tikz\node [vennbox] (box2){%
        $\dfrac{2}{5}$ \ \  $0{,}101232323\dots$
    }; 
};
\node[venntitle, right=10pt] at (box.north west) {Real numbers};
\node[venntitle, rounded corners] at (box.east) {$\mathbb{R}$};
\end{tikzpicture}%
%

\end{document}

enter image description here

As you can see, the set of reals is OK. The problem is that I don't know how to put a title and a symbol in the set of rational numbers (also at integers and natural numbers).

Thanks in advance!

1 Answer 1

1

Not prefect yet

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit,positioning, shapes,snakes}
\usepackage{amsmath,amssymb}

% fill=white is removed from "vennbox"
\tikzstyle{vennbox} = [draw,ultra thick,align=left,draw=black, very thick,  rounded corners=10, inner sep=10pt, inner ysep=20pt]
\tikzstyle{venntitle} =[fill=black, text=white]

\begin{document}

\begin{tikzpicture}[node distance=20pt]
  \node [vennbox] (rational){%
    $\dfrac{2}{5}$ \ \  $0{,}101232323\dots$
  };
  \node[above=of rational, inner sep=0pt] (irrational) {
    $\sqrt{2}$ \ $0{,}1010010001\dots$ \ \ $\pi$
  };
  \node [vennbox, fit=(rational) (irrational)] (real) {};

  \node[venntitle, right=10pt] at (real.north west) {Real numbers};
  \node[venntitle, above=10pt, rounded corners] at (real.east) {$\mathbb{R}$};
  \node[venntitle, right=10pt] at (rational.north west) {Rational numbers};
  \node[venntitle, rounded corners] at (rational.east) {$\mathbb{Q}$};
\end{tikzpicture}

\end{document}

enter image description here

Update

A complete example based on https://pastebin.com/zAr7d4Tz and following my personal taste, if not over-adjusted.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit,positioning}
\usepackage{amsmath,amssymb}
 

\tikzset{
  venn box/.style={
    draw=black, very thick, 
    rounded corners=10,
    inner xsep=10pt, inner ysep=15pt, outer ysep=5pt
  },
  venn numbers/.style={
%    draw,
    inner ysep=0pt,
    align=center
  },
  venn title/.style={
    fill=black, text=white
  }
}
 
\begin{document}
\begin{tikzpicture}[node distance=10pt]
  \node[venn box] (N) {%
      $0 \quad 1 \quad 12 \quad 350 \quad 48 \quad 5 \quad 16$
  };
  
  \node[venn numbers, below=of N] (Z-N) {
      $-1 \quad {-5} \quad {-10} \quad {-39}$
  };
  \node[venn box, fit=(Z-N) (N)] (Z) {};
  
  \node[venn numbers, below=of Z, align=center] (Q-Z) {
      $25{,}3401401401\dots \quad 48{,}259$ \\[5pt]
      $-0{,}101232323\dots \quad \dfrac52 \quad {-\dfrac73}$
  };
  \node[venn box, fit=(Q-Z) (Z)] (Q) {};
  
  \node[venn numbers, below=of Q, inner sep=0pt, align=center] (R-Q) {
      $6{,}1010010001\dots \quad {-0{,}1234567\dots}$ \\[5pt]
      $\sqrt{2} \quad \pi$
  };
  \node [venn box, fit=(R-Q) (Q)] (R) {};
  
  \tikzset{every node/.style=venn title}
  \foreach \i/\j/\k in {N/Natual/0, Z/Integer/10pt, Q/Rational/10pt, R/Real/15pt} {
    \draw node[anchor=north west] at ([shift={(10pt, 3pt)}]\i.north west) {\j}
          node[rounded corners] at ([yshift=-\k]\i.east) {$\mathbb{\i}$};
  }
\end{tikzpicture}
\end{document}

enter image description here

4
  • 2
    You can play with inner sep and outer sep to reserve room for the titles. Jun 10, 2020 at 12:17
  • @muzimuzhi Z , thanks for your answer! I have used your code to create the Venn diagram of all number sets (pastebin.com/zAr7d4Tz). I believe that my code needs more aesthetic improvement. Do you have any suggestions for improvement? Jun 10, 2020 at 16:36
  • 1
    @KώσταςΚούδας I have appended an example based on yours to my answer, which represents my preference. Jun 11, 2020 at 8:44
  • @muzimuzhi Z , that's very nice! Problem solved! Jun 11, 2020 at 8:49

You must log in to answer this question.

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