1

I am creating a document for a colleague about Real Numbers and I have worked on the a Venn diagram for Real Numbers System. I found a code from this post to fill the halfs of the ellipse with different colors.

But here is my problem, whenever I try to place the circles or the math symbols, the figure get messy and the other figures just misplace the original position. I do not know whether there is something in the preamble that I could get rid off and solve the issue or something is missing in the code.

enter image description here

I will appreciate if you help me with this. Thanks in advance.

\documentclass[tikz]{standalone}
\usepackage{amssymb}
\usepackage{xcolor}
\usepackage[backgrounds]{tikz}

\makeatletter
\def\tikz@arc@opt[#1]{% over-write!
  {%
    \tikzset{every arc/.try,#1}%
    \pgfkeysgetvalue{/tikz/start angle}\tikz@s
    \pgfkeysgetvalue{/tikz/end angle}\tikz@e
    \pgfkeysgetvalue{/tikz/delta angle}\tikz@d
    \ifx\tikz@s\pgfutil@empty%
      \pgfmathsetmacro\tikz@s{\tikz@e-\tikz@d}
    \else
      \ifx\tikz@e\pgfutil@empty%
        \pgfmathsetmacro\tikz@e{\tikz@s+\tikz@d}
      \fi%
    \fi
    \tikz@arc@moveto
    \xdef\pgf@marshal{\noexpand%
    \tikz@do@arc{\tikz@s}{\tikz@e}
      {\pgfkeysvalueof{/tikz/x radius}}
      {\pgfkeysvalueof{/tikz/y radius}}}%
  }%
  \pgf@marshal%
  \tikz@arcfinal%
}
\let\tikz@arc@moveto\relax
\def\tikz@arc@movetolineto#1{%
  \def\tikz@arc@moveto{\tikz@@@parse@polar{\tikz@arc@@movetolineto#1}(\tikz@s:\pgfkeysvalueof{/tikz/x radius} and \pgfkeysvalueof{/tikz/y radius})}}
\def\tikz@arc@@movetolineto#1#2{#1{\pgfpointadd{#2}{\tikz@last@position@saved}}}
\tikzset{%
  move to start/.code=\tikz@arc@movetolineto\pgfpathmoveto,%
  line to start/.code=\tikz@arc@movetolineto\pgfpathlineto}
\makeatother


\begin{document}

\begin{center}
\begin{tikzpicture}[x radius=7cm, y radius=4cm, white, ultra thick]
\centering
  \draw[fill=blue] (C) arc [line to start, start angle=90, delta angle=-180] -- cycle;
  \draw[fill=blue!70] (C) arc [line to start, start angle=90, delta angle=180] -- cycle;
\draw[white, fill=blue!55, ultra thick] (-3,0.25) circle [radius=2.75];
\draw[white, fill=blue!45, ultra thick] (-2.5,-1) circle [radius=1.75];
\node at (1,4.5){\huge $\mathbb{R}$};
\node[white] at (-0.75,2.5){\huge $\mathbb{Q}$};
\node[white] at (3.75,0.25){\huge $\mathbb{I}$};
\node[white] at (-2.25,2){\huge $\mathbb{Z}$};
\node[white] at (-2.25,-0.75){\huge $\mathbb{N}$};
\end{tikzpicture}
\end{center}

\end{document}

UPDATE

I've attempted another way with this simple code

\documentclass[tikz]{standalone}
\usepackage{amssymb}
\usepackage{xcolor}

\begin{document}

\begin{tikzpicture}
\draw[white, fill=blue!75, very thick] (1,0) circle [x radius=7cm, y radius=4cm];
\draw[white, fill=blue!55, ultra thick] (-2.25,0) circle [radius=2.75];
\draw[white, fill=blue!45, ultra thick] (-2.25,-0.75) circle [radius=1.75];
\draw[ultra thick, white] (1,-4)--(1,4);
\node[blue] at (1,4.5){\Huge $\mathbb{R}$};
\node[white] at (0,3){\Huge $\mathbb{Q}$};
\node[white] at (4,0){\Huge $\mathbb{I}$};
\node[white] at (-2.25,2){\Huge $\mathbb{Z}$};
\node[white] at (-2.25,-0.75){\Huge $\mathbb{N}$};
\end{tikzpicture}

\end{document}

However, I still do not figure out how to color both parts of the ellipse.

Cragfelt
  • 4,005
  • 5
    your diagram is relative simple: you need to define two shapes for nodes (circle, ellipse) star drawing with ellipse and then adding circle. without showing any your effort to draw this image your question is "do-it-for-me" which is unlikely to be answered. welcome to tex.se! – Zarko Aug 23 '17 at 08:32
  • 1
    Yes, you are right! Thank you for the feedback. I'll do my job and try to follow your advice on this. When Imake any progress, I will add it to my question if necessary. – Cragfelt Aug 23 '17 at 09:08
  • 1
    BTW, the general term for this is a Venn diagram. – John Kormylo Aug 23 '17 at 13:02
  • Related: https://tex.stackexchange.com/questions/69359/how-draw-nested-mathemathical-sets – PatrickT Jan 22 '24 at 07:56

2 Answers2

2

not perfect but hopeful close enough to what you like obtain:

enter image description here

\documentclass[tikz,margin=3mm]{standalone}
\usepackage{amssymb}
\usetikzlibrary{backgrounds, fit, positioning, scopes, shapes}

\begin{document}
    \begin{tikzpicture}[
node distance = 0mm and 16mm,
C/.style args = {#1/#2}{circle, draw=white, thick,
                 minimum size=#1,
                 fill=#2,
                 text=white},
     E/.style = {ellipse, draw=blue!80!black, fill=blue!80!white,
                 shift={(0.6,0)}, inner sep=0mm},
every label/.append style = {yshift=-0.5mm, text=white}
                        ]
\node (Z) [C=20mm/blue!50,
           label={[anchor=north]above:$\mathbb{Z}$}]                    {};
\node (W) [C=15mm/blue!30,above=of Z.south,
           label={[anchor=north,name=LW]above:{$\{\mathbb{N},0\}$}}]    {};
\node (N) [C=10mm/blue!30,above=of Z.south]                             {$\mathbb{N}$};
%
\coordinate[above right=2.5mm and 14mm of Q.north]    (a);
\coordinate[below right=2.5mm and 14mm of Q.south]    (b);
\begin{scoped}[on background layer]
    \fill[blue!80]
        (a) -- (b) arc (270:90:{33mm and 15mm});
    \fill[fill=blue]
        (a) -- (b) arc (-90:90:{33mm and 15mm});
    \draw[white,thick]
        (a) node [above,text=black] {$\mathbb{R}$} --
            node [right=11mm] {$\mathbb{I}$} (b);
\end{scoped}
    \end{tikzpicture}
\end{document}
Zarko
  • 296,517
  • Close enough. However there is a math misconception on your diagram and I think was derived from my messy attempt at first. I mean, the IR symbol cannot be placed as you did but outside the diagram. Anyway, I still want to know how to fill both halfs of the ellipse in different colors, so we can appreciate the differences of all the sets involved. – Cragfelt Aug 24 '17 at 07:37
  • @DiegoAguilar, see edited answer. regarding R sets it is not clear, if you like to have additional shell for it. – Zarko Aug 24 '17 at 09:38
1

I found the solution

\documentclass[tikz]{standalone}
\usepackage{amssymb}
\usepackage[backgrounds]{tikz}

\begin{document}

\begin{center}
\begin{tikzpicture}[x radius=7cm, y radius=4cm, white, ultra thick]
\centering
\draw[fill=blue] (0,4) arc [start angle=90, delta angle=-180] -- cycle;
\draw[fill=blue!75] (0,4) arc [start angle=90, delta angle=180] -- cycle;
\draw[white, fill=blue!55, ultra thick] (-3.25,0) circle [radius=2.75];
\draw[white, fill=blue!40, ultra thick] (-3.25,-0.75) circle [radius=1.75];
\node[blue!70!black] at (0,4.75){\Huge $\R$};
\node[white] at (-1,3){\Huge $\mathbb{Q}$};
\node[white] at (3,0){\Huge $\mathbb{I}$};
\node[white] at (-3.25,1.75){\Huge $\mathbb{Z}$};
\node[white] at (-3.25,-0.75){\Huge $\mathbb{N}$};
\end{tikzpicture}
\end{center}

\end{document}

enter image description here

Cragfelt
  • 4,005