如果我有这个矩阵代码,
\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}
有没有办法从某些变量“m”(表示行)和“n”(表示列)中提取矩阵维度,而无需手动计算它们?
答案1
事实上,这非常简单。
\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}