Tikz Matrix with Math and Numbers

I am using Tikz to draw an array of arbitrary length $n$. Below is a MWE

\begin{tikzpicture}
\matrix [
matrix of math nodes,
nodes={
rectangle,
draw,
minimum size=\ReservoirCellDim,
fill=white,
},
] (res)
{
1 & 2 & \cdots & n & 5n & \cdots1 \\
};
\end{tikzpicture}


Cells that contain exclusively math symbols (e.g., $\cdots$) or letters ($n$) are offset from others cells. If I mix numbers and a symbol/letter, the cells are aligned as expected. How do I fix this issue?

• Has there been a reason for unaccepting the answer? Jun 2, 2018 at 11:51
• My apologies. It was inadvertent. Jun 2, 2018 at 11:55
• No problem, I just wondered if I should improve something :) Jun 2, 2018 at 12:01

You can solve this by using anchor=center which doesn't really care about the content's baseline and size.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix [
matrix of math nodes,
nodes={
rectangle,
draw,
minimum size=1cm,
fill=white,
anchor=center
},
] (res)
{
1 & 2 & \cdots & n & 5n & \cdots1 \\
};
\end{tikzpicture}
\end{document}