# Tikz node text misplaced

I am trying to create a box of fixed size with some text in the center using tikz, but I am having some problems positioning text. I compile the following code:

\begin{tikzpicture}
\draw (0,0) rectangle (3, 1.5);
\node (2,2) {C};
\end{tikzpicture}


However, the result is not as expected, the C shows up in the bottom left corner instead of somewhat to the center just below or above the rectangle (I always forget direction of coordinates, so am not sure whether it should be below or above):

Furthermore, changing the nodes coordinates doesn't seem to change anything. The tikz picture is compiled within a figure environment, but I wouldn't expect that to change anything. What is going wrong here?

• the code is \node at (2,2) {C}; – AndréC Dec 28 '17 at 13:59
• thank you, that fixed it, if you submit it as an answer i will mark it as such – davidv1992 Dec 28 '17 at 13:59

Furthermore, changing the nodes coordinates doesn't seem to change anything. The tikz picture is compiled within a figure environment, but I wouldn't expect that to change anything. What is going wrong here?

You have omitted the at that indicates where to place the node as indicated on page 214 of the manual version 3.0.1a:

\path ... node <foreach statements> [<options>](<name>) at (<coordinate>){<node contents>} ...;

Add at allows you to place the node where you want it to be located:

\begin{tikzpicture}
\draw (0,0) rectangle (3, 1.5);
\node at (1.6,.75) {C};
\end{tikzpicture}


the code is self explanation:

\documentclass{article}
\usepackage{tikz}

\begin{document}%
\begin{tikzpicture}
\draw (0,0) rectangle (3, 1.5) node[midway] {C};
\end{tikzpicture}
or
\begin{tikzpicture}
\node[draw, minimum width=3cm, minimum height=1.5cm] {C};
\end{tikzpicture}

\end{document}


I dont't think including at, that was mentioned above solves the problem. Here is my way.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0,0) rectangle (3, 1.5);
\draw (1.5,0.75) node {C};
\end{tikzpicture}
\end{document}

• reads page 214 of the manual version 3.0.1a : The syntax for specifying nodes is the following: \path ... node foreach statements [options](name) at (coordinate){node contents} ...; – AndréC Dec 28 '17 at 15:58
• You are absolutely right. The first time i compiled your answer, something went wrong. Maybe i should have tried to compile it again. Now i see it works too. Sorry for the inconvenience. – chadoulis Dec 28 '17 at 16:06
• The first time @AndréC wrote \node at (2,2) {C};, that's why it didn't work, see the edit to his post. – CarLaTeX Dec 28 '17 at 17:20
• I recopied the code without modifying it and added atwhich answered the question of how to place the node where you want. – AndréC Dec 28 '17 at 17:23