# How to place a textnode at the center of a drawed rectangle

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.

-
Why not \node[draw,rectangle, minimum size=2cm] at (1,1){label};? –  Claudio Fiandrino Feb 1 '13 at 15:10
I had that approach before and i am now refactoring. I have trouble realigning my boxe´s if i dont explicitly state start and endpoints. –  Johannes Feb 1 '13 at 15:14
@Johannes: give a name to the node (e.g. \node[draw,rectangle, minimum size=2cm] (name) at (1,1){label};) then you will have name.south west for the lower left corner and name.north east for the upper right corner. –  Claudio Fiandrino Feb 1 '13 at 15:35

## 1 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.

-
You can also use [midway] option instead of [pos=.5]. It is equivalent and the syntax sounds perhaps a bit more natural. –  JLDiaz Feb 1 '13 at 16:45