如何在维恩图中添加标题?

如何在维恩图中添加标题?

我正在尝试制作数字集(实数、有理数、整数、自然数)的维恩图。我希望每个集合都有其标题和符号。

我试过这个代码

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

在此处输入图片描述

如您所见,实数集是可以的。问题是我不知道如何在有理数集中放置标题和符号(也适用于整数和自然数)。

提前致谢!

答案1

尚不完善

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

在此处输入图片描述

更新

完整的示例基于https://pastebin.com/zAr7d4Tz并符合我的个人品味,如果没有过度调整的话。

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

在此处输入图片描述

相关内容