我正在为同事创建一份关于实数的文档,并且我曾研究过实数系统的维恩图。我找到了一个代码这个帖子用不同的颜色填充椭圆的两半。
但我的问题是,每当我尝试放置圆圈或数学符号时,图形就会变得混乱,其他图形就会错位。我不知道序言中是否有我可以删除的东西来解决这个问题,或者代码中缺少了什么。
如果您能帮助我,我将不胜感激。提前致谢。
\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}
更新
我尝试用这个简单的代码以另一种方式
\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}
不过,我仍然不知道如何给椭圆的两个部分着色。
答案1
不完美但希望足够接近你喜欢的:
\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}
答案2
我找到了解决方案
\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}