Wie zeichne ich „verschachtelte“ mathematische Mengen?

Wie zeichne ich „verschachtelte“ mathematische Mengen?

Ich möchte mathematische Zahlenmengen (R, Z, N) mithilfe verschachtelter Kreise wie folgt darstellen:

Bildbeschreibung hier eingeben

Dies wurde sehr schnell mit Gimp erstellt, aber ich versuche, es in Tikz richtig zu machen, habe aber einige Probleme, hauptsächlich Kreise und zugehörige Beschriftungen zu platzieren. Ich brauche eine skalierbare Lösung. Welche Platzierungsstrategie soll ich verwenden? Ich habe es mit versucht

oben =2

usw., aber es skaliert nicht richtig?

Antwort1

Hier ist eine Möglichkeit, die Beschriftungen mit circle \nodes und der Bibliothek zu platzieren; sie ermöglicht Ihnen eine Skalierung:positioningscale=<factor>,transform shape

\documentclass{article} 
\usepackage{amssymb} 
\usepackage{tikz} 
\usetikzlibrary{positioning}

\tikzset{set/.style={draw,circle,inner sep=0pt,align=center}}

\begin{document} 

\begin{tikzpicture}
\node[set,fill=blue!20,text width=3cm,label={[below=85pt of rea,text opacity=1]$\mathbb{R}$}] 
  (nat) at (0,-0.4)  (rea) {};
\node[set,fill=red!20,text width=2cm,label={[below=55pt of int]$\mathbb{Z}$}] 
  (int) at (0,-0.2)  {};
\node[set,fill=olive!20,text width=1cm] (nat) at (0,0) {$\mathbb{N}$};
\end{tikzpicture}

\begin{tikzpicture}[scale=0.7,transform shape]
\node[set,fill=blue!20,text width=3cm,label={[below=85pt of rea]$\mathbb{R}$}] 
  (nat) at (0,-0.4)  (rea) {};
\node[set,fill=red!20,text width=2cm,label={[below=55pt of int]$\mathbb{Z}$}] 
  (int) at (0,-0.2)  {};
\node[set,fill=olive!20,text width=1cm] (nat) at (0,0) {$\mathbb{N}$};
\end{tikzpicture}

\begin{tikzpicture}[scale=2.5,transform shape]
\node[set,fill=blue!20,text width=3cm,label={[below=85pt of rea]$\mathbb{R}$}] 
  (nat) at (0,-0.4)  (rea) {};
\node[set,fill=red!20,text width=2cm,label={[below=55pt of int]$\mathbb{Z}$}] 
  (int) at (0,-0.2)  {};
\node[set,fill=olive!20,text width=1cm] (nat) at (0,0) {$\mathbb{N}$};
\end{tikzpicture}

\end{document}

Bildbeschreibung hier eingeben

Antwort2

Hier ist eine Lösung mit den Bibliotheken positioning, fit, und backgrounds.

Bildbeschreibung hier eingeben

Die Einleitung:

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

Das \drawnestedsetsMakro:

\newcommand\drawnestedsets[4]{
  % initial position
  \def\position{#1}
  % number of sets
  \def\nbsets{#2}
  % list of sets
  \def\listofnestedsets{#3}
  % reversed list of colors
  \def\reversedlistofcolors{#4}

  % position and draw labels of sets
  \coordinate (circle-0) at (#1);
  \coordinate (set-0) at (#1);
  \foreach \set [count=\c] in \listofnestedsets {
    \pgfmathtruncatemacro{\cminusone}{\c - 1}
    % label of current set (below previous nested set)
    \node[below=3pt of circle-\cminusone,inner sep=0]
    (set-\c) {$\mathbb{\set}$};
    % current set (fit current label and previous set)
    \node[circle,inner sep=0,fit=(circle-\cminusone)(set-\c)]
    (circle-\c) {};
  }

  % draw and fill sets in reverse order
  \begin{scope}[on background layer]
    \foreach \col[count=\c] in \reversedlistofcolors {
      \pgfmathtruncatemacro{\invc}{\nbsets-\c}
      \pgfmathtruncatemacro{\invcplusone}{\invc+1}
      \node[circle,draw,fill=\col,inner sep=0,
      fit=(circle-\invc)(set-\invcplusone)] {};
    }
  \end{scope}
}

Das Dokument:

\begin{document}
\begin{tikzpicture}
  \drawnestedsets{0,0}{4}{N,Z,R,C}{lime,orange,yellow,cyan}

  \begin{scope}[font=\tiny]
    \drawnestedsets{2,0}{3}{N,Z,R}{orange,yellow,cyan}
  \end{scope}
\end{tikzpicture}
\end{document}

Bearbeiten:Hier ist eine horizontale Variante mit Ellipsen:

Bildbeschreibung hier eingeben

Und der Code (Hinweis: Das \drawnestedsetsMakro ist eine modifizierte Version):

\documentclass{standalone}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tikz}
\usetikzlibrary{positioning,fit,backgrounds,shapes.geometric}

\newcommand\drawnestedsets[4]{
  % initial position
  \def\position{#1}
  % number of sets
  \def\nbsets{#2}
  % list of sets
  \def\listofnestedsets{#3}
  % reversed list of colors
  \def\reversedlistofcolors{#4}

  % position and draw labels of sets
  \coordinate (circle-0) at (#1);
  \coordinate (set-0) at (#1);
  \foreach \set [count=\c] in \listofnestedsets {
    \pgfmathtruncatemacro{\cminusone}{\c - 1}
    % label of current set (below previous nested set)
    \node[right=3pt of circle-\cminusone,inner sep=0]
    (set-\c) {$\mathbb{\set}$};
    % current set (fit current label and previous set)
    \node[ellipse,inner sep=0,fit=(circle-\cminusone)(set-\c)]
    (circle-\c) {};
  }

  % draw and fill sets in reverse order
  \begin{scope}[on background layer]
    \foreach \col[count=\c] in \reversedlistofcolors {
      \pgfmathtruncatemacro{\invc}{\nbsets-\c}
      \pgfmathtruncatemacro{\invcplusone}{\invc+1}
      \node[ellipse,draw,fill=\col,inner sep=0,
      fit=(circle-\invc)(set-\invcplusone)] {};
    }
  \end{scope}
}

\begin{document}
\begin{tikzpicture}
  \drawnestedsets{0,0}{4}{N,Z,R,C}{lime,orange,yellow,cyan}

  \begin{scope}[font=\tiny]
    \drawnestedsets{0,-1}{3}{N,Z,R}{orange,yellow,cyan}
  \end{scope}
\end{tikzpicture}
\end{document}

Antwort3

Die Antworten von Gonzalos und Paul sind ausgezeichnet. Ich füge der Abwechslung halber meine Version hier hinzu. Sie ist in vielerlei Hinsicht minderwertig, aber ich habe mir bei der Auswahl der Farben Mühe gegeben:

Bildbeschreibung hier eingeben

% author: Patrick TOCHE, 21 Jan 2024.
\documentclass[border=3pt]{standalone}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{amsfonts}
\usepackage{kpfonts}

\newcommand{\N}{\ensuremath{\mathbb{N}} }% set of natural numbers
\newcommand{\Z}{\ensuremath{\mathbb{Z}} }% set of integers
\newcommand{\Q}{\ensuremath{\mathbb{Q}} }% set of rational numbers
\newcommand{\R}{\ensuremath{\mathbb{R}} }% set of real numbers
\newcommand{\C}{\ensuremath{\mathbb{C}} }% set of complex numbers
\renewcommand{\H}{\ensuremath{\mathbb{H}} }% set of hypercomplex numbers
\newcommand{\T}{\ensuremath{\mathbb{T}} }% set of transcendental numbers

\newcommand{\e}{\mathrm{e}}% exponential number

\newcommand{\definitions}{%
  % color of set of Natural numbers
  \colorlet{colN}{OrangeRed!60}
  % color of set of Integers
  \colorlet{colZ}{Orange!60}
  % color of set of Rational numbers
  \colorlet{colQ}{Gold!60}
  % color of set of Real numbers
  \colorlet{colR}{ForestGreen!50}
  % color of set of Complex numbers
  \colorlet{colC}{CornflowerBlue!80}
  % color of set of Hypercomplex numbers
  \colorlet{colH}{BlueViolet!50}
  % color of set of Transcendental numbers
  \colorlet{colT}{Green!30}

  % center coordinate of Natural numbers
  \coordinate (oN) at (0.0, 0.0);
  % center coordinate of Integers
  \coordinate (oZ) at (0.5, 0.5);
  % center coordinate of Rational numbers
  \coordinate (oQ) at (1.0, 1.0);
  % center coordinate of Real numbers
  \coordinate (oR) at (1.5, 1.5);
  % center coordinate of Complex numbers
  \coordinate (oC) at (2.0, 2.0);
  % center coordinate of Hypercomplex numbers
  \coordinate (oH) at (2.5, 2.5);
  % center coordinate of Transcendental numbers
  \coordinate (oT) at (0.5, 4.7);

  % set of Natural numbers
  \def\setN{(oN) ellipse (2.5 and 1.0)}
  % set of Integers
  \def\setZ{(oZ) ellipse (3.5 and 2.0)}
  % set of Rational numbers
  \def\setQ{(oQ) ellipse (4.5 and 3.0)}
  % set of Real numbers
  \def\setR{(oR) ellipse (5.5 and 4.0)}
  % set of Complex numbers
  \def\setC{(oC) ellipse (6.5 and 5.0)}
  % set of Hypercomplex numbers
  %\def\setH{(oH) ellipse (7.5 and 6.0)}
  % set of Transcendental numbers
  \def\setT{(oT) ellipse (1.5 and 0.67)}
}

\begin{document}
\begin{tikzpicture}
  
  % define colors and sets
  \definitions

  % fill sets in reverse order of size
  %\filldraw[fill=colH]\setH;
  \filldraw[fill=colC]\setC;
  \filldraw[fill=colR]\setR;
  \filldraw[fill=colQ]\setQ;
  \filldraw[fill=colZ]\setZ;
  \filldraw[fill=colN]\setN;
  %\filldraw[fill=colT]\setT;

  % add set label for each set
  \node[font=\huge] (N) at (-.2, 0.5) {\N};
  \node[font=\huge] (Z) at (0.8, 2.0) {\Z};
  \node[font=\huge] (Q) at (1.8, 3.5) {\Q};
  \node[font=\huge] (R) at (2.8, 4.9) {\R};
  \node[font=\huge] (C) at (3.8, 6.3) {\C};
  %\node[font=\huge] (H) at (4.8, 7.8) {\H};
  %\node[font=\large] (T) at (0.8, 4.9) {\T};

  % add name label for each set
  \node[font=\large] [below=0ex of N] {Natural};
  \node[font=\large] [below=0ex of Z] {Integer};
  \node[font=\large] [below=0ex of Q] {Rational};
  \node[font=\large] [below=0ex of R] {Real};
  \node[font=\large] [below=0ex of C] {Complex};
  %\node[font=\large] [below=0ex of H] {Hypercomplex};
  %\node[font=\small] [below=-1ex of T] {Transcendental};

  % add number examples for each set
  \node[font=\small] [below right=3.5ex and -1em of N] {$1,2,3,4$};
  \node[font=\small] [below right=3.5ex and 1.5em of Z] {$-4,-3,-2,-1$};
  \node[font=\small] [below right=3.5ex and 2em of Q] {$-\frac{1}{2},\frac{22}{7},\frac{355}{113}$};
  \node[font=\small,align=left] [below right=1.5ex and 1em of R] {$\sqrt{2},\sqrt{3},\varphi$,\\ \quad$\pi,\e,\gamma$};
  \node[font=\small] [below right=3.5ex and 1em of C] {$\sqrt{-1},i,\sqrt{i},\e^{i}$};
  %\node[font=\small] [below right=3.5ex and -1em of H] {Hypercomplex};
  %\node[font=\small] [below=1ex of T] {$\pi,\e,\gamma$};

\end{tikzpicture}
\end{document}

verwandte Informationen