[Tex/LaTex] How to place a textnode at the center of a drawn rectangle

labelsnodestikz-pgf

A rectangle label does not appear inside the rectangle but on the corner of it.

  \tikzstyle{every node} = [align=center]
   \begin{tikzpicture}
    \draw (0, 0) rectangle (2, 2) node [center] {label}; 
     %center is unknown but was my best guess
  \end{tikzpicture}

How do I move the labelling node to have a common center with the rectangle?

The result should look like this

  \tikzstyle{every node} = [align=center]
  \begin{tikzpicture}
    \draw (0, 0) rectangle (2, 2);
    \node at (1,1) {label};
  \end{tikzpicture}

but without having to specify the center manually.

Best Answer

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.

Image Description