How to force nodes to have the same size in tikz matrices

Using text depth and text height, you can control the total height for the nodes; text width gives you control over the width (there's also a minimum size key which could be used):

\documentclass{article}    
\usepackage[svgnames]{xcolor}
\usepackage{tikz}


\begin{document}
\begin{tikzpicture}[every node/.style={anchor=base,text depth=.5ex,text height=2ex,text width=1em}]
\matrix [draw=red]
{
\node[fill=Orange] {a}; & \node[fill=Green] {X}; & \node[fill=LightGreen] {g}; \\
\node[fill=Yellow] {a}; & \node[fill=Cyan] {X}; & \node[fill=Magenta] {g}; \\
\node[fill=Purple] {a}; & \node[fill=LightBlue] {X}; & \node[fill=Aquamarine] {g}; \\
};
\end{tikzpicture}
\end{document}

enter image description here

As percusse mentions in his comment, a matrix of nodes (requires the matrix library) could be more useful here; it simplifies the code and also gives you a nodes in empty cells key to deal with the case of cells without explicit text:

\documentclass{article}    
\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}
\begin{tikzpicture}[every node/.style={anchor=base,text depth=.5ex,text height=2ex,text width=1em}]
\matrix [matrix of nodes,draw=red,nodes in empty cells]
{
|[fill=Orange]| a & |[fill=Green]| X & |[fill=LightGreen]| \\
|[fill=Yellow]| a & |[fill=Cyan]| & |[fill=Magenta]| g \\
|[fill=Purple]| & |[fill=LightBlue]| X & |[fill=Aquamarine]| g \\
};
\end{tikzpicture}
\end{document}

enter image description here


This does what I want, but it's admittedly not pretty. It's motivated by Dependent node size in TikZ .

I'm puzzled why using

column 1/.style={Minimum Width=c1} 

etcetera doesn't work the same way as the row style commands. Thanks all.

\documentclass[12pt]{article}

\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{positioning,node-families,matrix}

\begin{document}



\begin{tikzpicture}[every node/.style={anchor=base}, 
row 1/.style={Minimum Height=r1,Text Height=th1,Text Depth=td1},
row 2/.style={Minimum Height=r2,Text Height=th2,Text Depth=td2},
row 3/.style={Minimum Height=r3,Text Height=th3,Text Depth=td3}
]
\matrix [matrix of nodes,draw=Red,nodes in empty cells]
{
|[fill=Orange,Minimum Width=col1]| a & |[fill=Green,Minimum Width=col2]| X & |[fill=LightGreen,Minimum Width=col3]| \\
|[fill=Yellow,Minimum Width=col1]| a & |[fill=Cyan,Minimum Width=col2]| & |[fill=Magenta,Minimum Width=col3]| g \\
|[fill=Purple,Minimum Width=col1]| & |[fill=LightBlue,Minimum Width=col2]| X & |[fill=Aquamarine,Minimum Width=col3]| \tikz\draw[fill=Black]  (0,0) circle(1cm); \\
};
\end{tikzpicture}

\end{document}