这与突出圆形节点之间的重叠的问题密切相关突出显示节点之间的重叠并从节点边缘绘制箭头。但是有一个新的角度:如何将其推广到椭圆(我想还有其他形状,但目前我关心的是椭圆)。
您可能希望以下代码用绿色填充椭圆之间的重叠部分:
\documentclass{article}
\usepackage{tikz}
\newcommand*{\MyRadius}{7cm}
\begin{document}
\def\A{(0,0) ellipse [minimum width = 2*\MyRadius, minimum height = \MyRadius]}
\def\B{(8,0) ellipse [minimum width = 2*\MyRadius, minimum height = \MyRadius]}
\begin{tikzpicture}
\node[draw, shape=ellipse, minimum width=2*\MyRadius, minimum height=\MyRadius, ultra thick] (A) at (0,0) {};
\node[draw, shape=ellipse, minimum width=2*\MyRadius, minimum height=\MyRadius, ultra thick] (B) at (8,0) {};
\begin{scope}
\clip \A;
\fill[green, opacity=0.2] \B;
\end{scope}
\end{tikzpicture}
\end{document}
但事实并非如此。我还尝试以 (x, y) 格式指定椭圆的高度和宽度,而不是方括号,但这更糟糕(产生错误)。
答案1
请注意,路径ellipse
具有参数x radius
和y radius
,而形状ellipse
不是预定义的,但可以在shapes.geometric
库中找到,并且minimum width
具有“x
直径”。考虑到这一点后,您可以使用与圆相同的代码类型:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\newcommand*{\MyRadius}{2cm}
\begin{document}
\def\A{(0,0) ellipse [x radius = 2*\MyRadius, y radius = \MyRadius]}
\def\B{(4,0) ellipse [x radius = 2*\MyRadius, y radius = \MyRadius]}
\begin{tikzpicture}
\node[draw, shape=ellipse, minimum width=4*\MyRadius, minimum height=2*\MyRadius, ultra thick] (A) at (0,0) {};
\node[draw, shape=ellipse, minimum width=4*\MyRadius, minimum height=2*\MyRadius, ultra thick] (B) at (4,0) {};
\begin{scope}
\clip \A;
\fill[green, opacity=0.2] \B;
\end{scope}
\end{tikzpicture}
\end{document}
添加节点连接类似操作作为圆形案例现在也可以按预期工作:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\newcommand*{\MyRadius}{2cm}
\begin{document}
\def\A{(0,0) ellipse [x radius = 2*\MyRadius, y radius = \MyRadius]}
\def\B{(4,0) ellipse [x radius = 2*\MyRadius, y radius = \MyRadius]}
\begin{tikzpicture}
\node[draw, shape=ellipse, minimum width=4*\MyRadius, minimum height=2*\MyRadius, ultra thick] (A) at (0,0) {};
\node[draw, shape=ellipse, minimum width=4*\MyRadius, minimum height=2*\MyRadius, ultra thick] (B) at (4,0) {};
\begin{scope}
\clip \A;
\fill[green, opacity=0.2] \B;
\end{scope}
\node(nom) at (0,-3) {[A]};
\node(gen) at (4,-3) {[B]};
\draw[->] (A) -- (nom);
\draw[->] (B) -- (gen);
\end{tikzpicture}
\end{document}
答案2
这个答案@Kpym 也适用于其他形状,因为不需要通过路径重现节点。
\documentclass[tikz,border=1cm]{standalone}
\usetikzlibrary{shapes.geometric}
\newcommand*{\MyRadius}{2cm}
\tikzset{
myellipse/.style={draw, shape=ellipse, minimum width=4*\MyRadius, minimum height=2*\MyRadius, ultra thick}
}
\begin{document}
\begin{tikzpicture}
\node[myellipse,
path picture={\node[myellipse,fill=green,opacity=0.2] at (4,0){};}
]at(0,1) (A){};
\node[myellipse] (B) at (4,1){};
\end{tikzpicture}
\end{document}
或者另一个例子:
\documentclass[tikz,border=1cm]{standalone}
\usetikzlibrary{shapes.symbols}
\newcommand*{\MyRadius}{2cm}
\tikzset{
myecloud/.style={draw, shape=cloud, minimum width=3*\MyRadius, minimum height=2*\MyRadius, ultra thick}
}
\begin{document}
\begin{tikzpicture}
\node[mycloud,
path picture={\node[mycloud,fill=green,opacity=0.2] at (4,0){};}
]at(0,1) (A){};
\node[mycloud] (B) at (4,1){};
\end{tikzpicture}
\end{document}