Center node in tikz matrix cell

tikz-matrixtikz-pgf

How do I center a node in the middle of a tikz matrix cell?

This MWE:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\tikzset{mynode/.style={rectangle,draw,minimum width=2cm,minimum height=1cm}}
\begin{tikzpicture}
\matrix[row sep=1cm]{
\node[mynode] {A}; \\
\node[mynode] {B}; \node[mynode,right=2cm] {C}; \\};
\end{tikzpicture}
\end{document}

produces

enter image description here

How do I get the A node to be between (but still above) the B and C nodes? I know how to do this without using a tikz matrix, but this is for a more complicated diagram where the matrix is the easiest way to layout the rest of it.

Best Answer

One more solution, with use of matrix library:

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

\begin{document}
    \begin{tikzpicture}
\matrix[matrix of nodes,
        nodes={draw, minimum width=2cm, minimum height=1cm},
        row sep=1cm]
{
\node {A};   \\
\node[left=5mm] {B}; \node[right=5mm] {C};\\
};
    \end{tikzpicture}
\end{document}

enter image description here