tikz matrix alignment of empty cells [duplicate]

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}

\begin{tikzpicture}[
]
\matrix (m) [nodes in empty cells,
matrix of nodes,
execute at begin cell=\strut,
execute at empty cell=\strut,
nodes = {
red,
draw,
align=right,
minimum height=1cm,
minimum width=2cm,
inner sep=0pt,
},
]
{
A  & B    & y  \\
1  &      &    \\
2  &      &    \\
3  &      &    \\
};

\end{tikzpicture}

\end{document}


which gives:

Why the empty cells are misaligned? How can I solve this? (The \strut is necessary to avoid the same problem with descendant in "filled" cells, but why it is not working in the empty ones?)

marked as duplicate by Ignasi tikz-pgf StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Feb 19 '17 at 17:14

I don't think it is the content so much as the anchoring of the cells which is problematic. That is, you could fix it by fiddling with the content, no doubt, but setting the anchor for each cell is probably the most straightforward solution.

Try using anchor=center:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}

\begin{tikzpicture}[
]
\matrix (m) [nodes in empty cells,
matrix of nodes,
nodes = {
red,
draw,
align=right,
minimum height=1cm,
anchor=center,
minimum width=2cm,
inner sep=0pt,
},
]
{
A  & B    & y  \\
1  &      &    \\
2  &      &    \\
3  &      &    \\
};

\end{tikzpicture}

\end{document}