How to place a textnode at the center of a drawn rectangle
You should write instead:
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0,0) rectangle (2,2) node[pos=.5] {Test};
\end{tikzpicture}
\end{document}
By using node
in a path without option, it will position the node to the last point.
You can write the Text, that should be centered, after the connection (rectangle in this case). It also works for lines etc.
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0,0) rectangle node{Test} (2,2);
\end{tikzpicture}
\end{document}
It seems that OP wants to draw a rectangle on fixed coordinates and later on insert the label in its center.
By default a node
is a rectangle with a text in its center, so we could use it as an alternative.
Unfortunately node's solution needs some minimum width|height|size
(which is not always respected) and it seems that OP doesn't want to compute them.
As an alternative node
which does the work for us is a fit
node. In this case we can enter both corner coordinates and insert the text with a center
label. This solution has the advantage that we have created a correct size node
which be used later on in our diagram.
\node[draw, fit={(0,0) (2,2)}, inner sep=0pt, label=center:Test] (A) {};
Rectangle corners can be absolute or relative coordinates. In this case we can use a shift
option to place it where we want.
Following code shows both options, in blue Lionel or dexteritas solution and in black a fit
node.
\documentclass[tikz, border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{fit}
\begin{document}
\begin{tikzpicture}
\begin{scope}
\node[draw, fit={(0,0) (2,2)}, inner sep=0pt, label=center:Test] (A) {};
\node[draw, fit={(0,0) (2,2)}, xshift=3cm, inner sep=0pt, label=center:Test] (B) {};
\draw (A)--(B);
\end{scope}
\begin{scope}[draw=blue, yshift=2.5cm]
\draw (0,0) rectangle node[draw] (A) {Test} ++(2,2);
\draw (3,0) rectangle node[draw] (B) {Test} ++(2,2);
\draw (A)--(B);
\end{scope}
\end{tikzpicture}
\end{document}