How to make this rectangle a node (TikZ)?

You can specify the minimum height and minimum width for a node. In conjunction with draw, you'll end up with a rectangle with the specified dimensions:

\node (rect) at (4,2) [draw,thick,minimum width=2cm,minimum height=2cm] {};

Another solution with fit library. Following example shows how to use two opposite corner coordinates to define an rectangular node.

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{fit}

\begin{document}

\begin{tikzpicture}
    \draw[help lines] (0,0) grid (6,4);
    \fill[red] (3,1) circle (1pt) node[below left] {(3,1)} (5,3) circle (1pt) node[above right] {(5,3)};
    \node[fit={(3,1) (5,3)}, inner sep=0pt, draw=blue, thick] (rect) {};
    \draw[red] (rect.east) to[out=0,in=-90] (rect.south);
\end{tikzpicture}
\end{document}

enter image description here


You can define a node and put the rectagle inside. Then you can add more objets as nodes with relative posititions.

\documentclass[tikz,border=5]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}
  \node(cuadrado){
  \tikz {\draw[thick] (3,1) rectangle ++(2,2);}
  };

%Text inside the rectangle
\node[at={($(cuadrado.center)$)},anchor=center] (texto) {asd asd asd};

\end{tikzpicture}
\end{document}

Tags:

Tikz Pgf