# Vertical align in tikz matrix

\documentclass[a4paper,12pt]{report}

\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}

\begin{center}
\begin{tikzpicture}

\tikzset{square matrix/.style={
matrix of nodes,
column sep=-\pgflinewidth, row sep=-\pgflinewidth,
nodes={draw,
text height=#1/2+0.75ex,
text depth=#1/2-0.75ex,
text width=#1,
align=center,
inner sep=0pt
},
},
square matrix/.default=1.4cm
}

\matrix[square matrix]
{
|[fill=lightgray]|+ & |[fill=lightgray]|0 & |[fill=lightgray]|1 & |[fill=lightgray]|$\ldots$ &  |[fill=lightgray]|$\alpha^{2^m-3}$ & |[fill=lightgray]|$2^m - 1$\\
|[fill=lightgray]|0 & 0 & 1 & $\ldots$ &  $2^m - 2$ & $2^m - 1$\\
|[fill=lightgray]|1 & 1 & 0 & $\ldots$ &  $2^m - 2$ + 5465 1\\
|[fill=lightgray]|$\vdots$\\
|[fill=lightgray]|$2^m - 2$\\
|[fill=lightgray]|$2^m - 1$\\
};

\end{tikzpicture}
\end{center}

\end{document}


And output is:

Text in the right-bottom cell doesn't fit into cell. How to set vertical align of cell to center which will move this text a bit higher and it will fit into cell?

-

You should use

minimum height=#1,
anchor=center


text height=#1/2+0.75ex,
text depth=#1/2-0.75ex


This will make sure the text is vertically centered.

\documentclass[a4paper,12pt]{report}

\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}

\begin{center}
\begin{tikzpicture}

\tikzset{square matrix/.style={
matrix of nodes,
column sep=-\pgflinewidth, row sep=-\pgflinewidth,
nodes={draw,
minimum height=#1,
anchor=center,
text width=#1,
align=center,
inner sep=0pt
},
},
square matrix/.default=1.45cm
}

\matrix[square matrix]
{
|[fill=lightgray]|+ & |[fill=lightgray]|0 & |[fill=lightgray]|1 & |[fill=lightgray]|$\ldots$ &  |[fill=lightgray]|$\alpha^{2^m-3}$ & |[fill=lightgray]|$2^m - 1$\\
|[fill=lightgray]|0 & 0 & 1 & $\ldots$ &  $2^m - 2$ & $2^m - 1$\\
|[fill=lightgray]|1 & 1 & 0 & $\ldots$ &  $2^m - 2$ + 5465 1\\
|[fill=lightgray]|$\vdots$\\
|[fill=lightgray]|$2^m - 2$\\
|[fill=lightgray]|$2^m - 1$\\
};

\end{tikzpicture}
\end{center}

\end{document}


-