椭圆节点之间的颜色重叠

椭圆节点之间的颜色重叠

这与突出圆形节点之间的重叠的问题密切相关突出显示节点之间的重叠并从节点边缘绘制箭头。但是有一个新的角度:如何将其推广到椭圆(我想还有其他形状,但目前我关心的是椭圆)。

您可能希望以下代码用绿色填充椭圆之间的重叠部分:

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

在此处输入图片描述

相关内容