I am representing sets using ellipses and would like to draw the difference between two sets: B - A (blue area in the figure below).
Please consider the following code:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes, positioning}
\begin{document}
\begin{tikzpicture}
\def\A{(0,0) ellipse (2cm and 3cm)}
\def\B{(2,0) ellipse (3cm and 2cm)}
\draw[red] \A;
\draw[green] \B;
\begin{scope}
\clip \B;
\fill[blue,even odd rule] \B \A;
\end{scope}
\end{tikzpicture}
\end{document}
that produces:
However, I define the ellipses using nodes, because I need to assign names to them. Basically, my ellipses are defined as:
\node [draw,transform shape, fill=blue!5,draw=blue,line width=1pt,ellipse,minimum width=2cm,minimum height=1.5cm] (TP) at (1.2,2) {};
Basically, I use \node instead of the simpler ellipse path because I want to have that TP name.
If I try and plot the set difference using ellipses defined with \node instead of (0,0) ellipse (2cm and 3cm), the compilation fails.
I have two questions:
Q1) Can I give a name to ellipses defined as in the code above (i.e., without using
node)?Q2) How can I clip using a
\nodeand get the same result as in the picture above?
There is a question similar to this, but I am not able to comprehend the answers (too complex): Clipping a path using a node.
This is the actual tikz picture I am using:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes, positioning}
\begin{document}
\begin{tikzpicture}[scale=3]
% frame
\node [draw, transform shape, rectangle, minimum width=5cm, minimum height=3cm, anchor=south west] (F) at (0,0) {};
\node [below left] at (F.north east) {$U$};
\node [draw,transform shape, fill=blue!5,draw=blue,line width=1pt,ellipse,minimum width=2cm,minimum height=1.5cm] (TP) at (1.2,2) {};
\node [right] at (TP.west) {$A$};
\node [draw,transform shape,fill=red!5,draw=red,line width=1pt,ellipse,minimum width=2cm,minimum height=1.5cm] (TN) at (3.8,1) {};
\node [left] at (TN.east) {$B$};
\node [draw,transform shape,fill=green!5,draw=green, fill opacity=0.5, line width=1pt,ellipse,minimum width=2.5cm,minimum height=2cm] (COV) at (2.3,1.2) {};
\node [below right] at (COV.west) {$C$};
\end{tikzpicture}
\end{document}
Starting from that picture, I need to draw:
AC - A
I defined the ellipses using \node because I needed their names for anchor points.


spath3library to save the path of a node and then reuse it later to clip. It also has an interface for combining to paths (one for each node). On the other hand. Maybe all you need is areverse clipsolution. – Qrrbrbirlbel May 26 '23 at 22:35