5

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?

Tikz Math Mode Offset Issue

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

1 Answer 1

8

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

matrix

\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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.