如何绘制“嵌套”的数学集?

如何绘制“嵌套”的数学集?

我想使用嵌套圆圈来表示数学数字集(R,Z,N),如下所示:

在此处输入图片描述

这是用 gimp 很快创建的,但我试图在 tikz 中正确完成它,但遇到了一些问题,主要是放置圆圈和相关标签。我需要一个能够扩展的解决方案。我应该使用什么放置策略,我尝试过

以上 =2

等等但它不能正确扩展?

答案1

circle \node这是一个使用s 和positioning库放置标签的选项;scale=<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}

在此处输入图片描述

答案2

positioning以下是使用、fit和库的解决方案backgrounds

在此处输入图片描述

序言:

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

\drawnestedsets

\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}
}

该文件:

\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}

编辑:以下是带有省略号的水平变体:

在此处输入图片描述

代码如下(注意:\drawnestedsets宏是修改后的版本):

\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}

答案3

Gonzalo 和 Paul 的回答非常出色。为了增加多样性,我在这里添加了我的版本。它在很多方面都不如别人,但我确实在选择颜色方面花了不少功夫:

在此处输入图片描述

% 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}

相关内容