다음과 같이 중첩된 원을 사용하여 수학적 숫자 집합(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}