3

If I have this matrix code,

  \begin{tikzpicture}
  \matrix[matrix of math nodes, anchor=south west,
  nodes={
  draw=red,
  align=center, 
  inner sep=0pt,
  text width=1cm - \pgflinewidth,
  minimum size = 1cm - \pgflinewidth
  }
  ]{
    A & B & D & B & A & C & E & G & E & H & E & C & F & I & F & C & A \\
    0 & 1 & 2 & 1 & 0 & 1 & 2 & 3 & 2 & 3 & 2 & 1 & 2 & 3 & 2 & 1 & 0 \\
  };
 \end{tikzpicture}

there is a way to extrac the matrix dimension in some variable "m" (for the rows) and "n" (for the columns) without counting them manually?

7

Actually, it is pretty easy.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}
  \noindent\begin{tikzpicture}
  \matrix[matrix of math nodes, anchor=south west,
  nodes={
  draw=red,
  align=center, 
  inner sep=0pt,
  text width=0.5cm - \pgflinewidth,
  minimum size = 0.5cm - \pgflinewidth
  }
  ]{
    A & B & D & B & A & C & E & G & E & H & E & C & F & I & F & C & A \\
    0 & 1 & 2 & 1 & 0 & 1 & 2 & 3 & 2 & 3 & 2 & 1 & 2 & 3 & 2 & 1 & 0 \\
  };
 \end{tikzpicture}

\the\pgfmatrixcurrentrow{ by }\the\pgfmatrixcurrentcolumn
\end{document}

demo

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.