Unfortunately, I am not able to understand the basics of Tikz.
I would like to draw a rectangle with two ellipses in it. I need to add labels and would like to use anchor points. Please look at the following code:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,positioning}
\begin{document}
1.
\begin{tikzpicture}
% frame
\draw (0,0) rectangle (5, 3);
\node [draw,fill=blue!20,draw=blue,line width=1pt,ellipse,minimum width=2cm,minimum height=1.5cm] (TP) at (1.5,2) {};
\node [right] at (TP.west) {$A$};
\node [draw,fill=red!20,draw=red,line width=1pt,ellipse,minimum width=2cm,minimum height=1.5cm] (TN) at (3.5,1) {};
\node [right] at (TN.west) {$B$};
\end{tikzpicture}
2.
\begin{tikzpicture}
% frame
\node [draw,rectangle,minimum width = 5cm, minimum height = 3cm] (F) at (0,0) {};
\node [below left] at (F.north east) {U};
\node [draw,fill=blue!20,draw=blue,line width=1pt,ellipse,minimum width=2cm,minimum height=1.5cm] (TP) at (1.5,2) {};
\node [right] at (TP.west) {$A$};
\node [draw,fill=red!20,draw=red,line width=1pt,ellipse,minimum width=2cm,minimum height=1.5cm] (TN) at (3.5,1) {};
\node [right] at (TN.west) {$B$};
\end{tikzpicture}
\end{document}
that outputs:
The first one (1.) is correct, but I would like to add the label U
as in the second one (2.), using anchor points.
When I substitute (in 1.):
\draw (0,0) rectangle (5, 3);
with (see 2.):
\node [draw,rectangle,minimum width = 5cm, minimum height = 3cm] (F) at (0,0) {};
the picture that comes out is not correct. The two ellipses are placed outside of the rectangle.
Why? It should be related to the dimensions of the rectangle but I cannot really understand the problem with 2.
rectangle (5, 3)
will draw a rectangle that is 5cm times 3cm big. On the other hand in your node the rectangle will be (5cm + inner-sep) times (3cm + inner-sep). If you want to get your exact dimensions addinner sep=0
to your node's options.