# Why are empty and non empty TikZ matrix cells not equally placed?

I wanted to draw an almost empty matrix of nodes with TikZ similar to the left most one below. All nodes would have same size (through minimum width and minimum height) and no separation between columns and rows. But when I include a text which needs two lines I obtain the central matrix and, if the text just needs one line the right most one. I don't know what's wrong. Do you? I'm using CVS version of TikZ.

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{matrix}

\tikzset{
proces/.style={draw, minimum height=15mm, minimum width=2cm, outer sep=0pt, text width=1.5cm, align=center}
}

\begin{document}
\begin{tikzpicture}

\matrix (A) [matrix of nodes,nodes=proces,nodes in empty cells] {
& \\
& \\
};

\begin{scope}[xshift=4.5cm]
\matrix (A) [matrix of nodes,nodes=proces,nodes in empty cells] {
& OOO OOO \\
& \\
};
\end{scope}

\begin{scope}[xshift=9cm]
\matrix (B) [matrix of nodes,nodes=proces,nodes in empty cells] {
& A \\
& \\
};
\end{scope}

\end{tikzpicture}
\end{document}


-
Weigh anchor and hoist sail for TikZland. Seriously, try nodes={anchor=center}. The style matrix of nodes automatically sets the anchor to base and I suspect (only suspect) that this is the cause of the shifts. –  Loop Space Oct 24 '12 at 17:54
@AndrewStacey Verified. Godspeed... –  percusse Oct 24 '12 at 20:15
@AndrewStacey: Perfect! Thank you! Do you want to write an answer? –  Ignasi Oct 25 '12 at 6:32
Sure. Bit later today. –  Loop Space Oct 25 '12 at 7:08

## 1 Answer

What's happened here is that the matrix of nodes has quietly set anchor=base on each of your matrix subnodes. The problem with this is that when the node has text in it then the base anchor is not in the same place as the center anchor. So your nodes are lining up so that their bases are in a line but this means that their centers (and thus their boundary) are not.

The simplest solution is to put nodes={anchor=center}, or you could add it to the proces style, after the matrix of nodes to revert this change.

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{matrix}

\tikzset{
process base/.style={
draw,
minimum height=15mm,
minimum width=2cm,
outer sep=0pt,
text width=1.5cm,
align=center
}
}

\begin{document}
\begin{tikzpicture}[
proces/.style={
process base,
}
]

\matrix (A) [matrix of nodes,nodes=proces,nodes in empty cells] {
& \\
& \\
};

\begin{scope}[xshift=4.5cm]
\matrix (B) [matrix of nodes,nodes=proces,nodes in empty cells] {
& OOO OOO \\
& \\
};
\end{scope}

\begin{scope}[xshift=9cm]
\matrix (C) [matrix of nodes,nodes=proces,nodes in empty cells] {
& A \\
& \\
};
\end{scope}

\foreach \lbl in {A,B,C} {

\draw[line width=3mm,green] (\lbl-1-1.base) -- (\lbl-1-2.base);
\draw[ultra thick,red] (\lbl-1-1.center) -- (\lbl-1-2.center);

}
\end{tikzpicture}

\begin{tikzpicture}[
proces/.style={
process base,
anchor=center,
}
]

\matrix (A) [matrix of nodes,nodes=proces,nodes in empty cells] {
& \\
& \\
};

\begin{scope}[xshift=4.5cm]
\matrix (B) [matrix of nodes,nodes=proces,nodes in empty cells] {
& OOO OOO \\
& \\
};
\end{scope}

\begin{scope}[xshift=9cm]
\matrix (C) [matrix of nodes,nodes=proces,nodes in empty cells] {
& A \\
& \\
};
\end{scope}

\foreach \lbl in {A,B,C} {

\draw[line width=3mm,green] (\lbl-1-1.base) -- (\lbl-1-2.base);
\draw[ultra thick,red] (\lbl-1-1.center) -- (\lbl-1-2.center);

}

\end{tikzpicture}

\end{document}


-