在节点样式定义矩阵中使用 \pgfmatrixcurrentrow 作为标签的问题

在节点样式定义矩阵中使用 \pgfmatrixcurrentrow 作为标签的问题

matrix以下代码展示了为 a或中的某些节点添加标签及其列和行值的四种不同方法matrix of nodes。问题是第四种方法(在代码中注释)不起作用。编译以错误结束

! TeX capacity exceeded, sorry [grouping levels=255].
\pgfutil@g@addto@macro #1#2->\begingroup 
                                         \pgfutil@toks@ \expandafter {#1#2}\...
l.37    D\\

!  ==> Fatal error occurred, no output PDF file produced!

你能解释一下为什么吗?matrix of nodes尊重有限吗matrix

\documentclass[tikz,border=2mm]{standalone} 
\usetikzlibrary{positioning, matrix}

\begin{document}
\begin{tikzpicture}

\matrix (a) 
{
    \node[draw, 
        label=left:\the\pgfmatrixcurrentrow, 
        label=\the\pgfmatrixcurrentcolumn] {A};\\
};

\matrix (b) [right = 1mm of a, 
    matrix of nodes,
    nodes = {draw}] 
{
    |[label=left:\the\pgfmatrixcurrentrow, 
        label=\the\pgfmatrixcurrentcolumn]| B\\
};

\matrix (c) [right = 3mm of b.south east, matrix anchor=south west,
    matrix of nodes,
    nodes = {draw}] 
{
    C\\
};
\node also [label=left:\the\pgfmatrixcurrentrow, 
        label=\the\pgfmatrixcurrentcolumn] (c-1-1) {};

%This labelling way doesn't work. 
%\matrix (d) [right= of c,
%       matrix of nodes,
%       nodes={draw, 
%           label=left:\the\pgfmatrixcurrentrow, 
%           label=\the\pgfmatrixcurrentcolumn}] 
%{
%   D\\
%};

\end{tikzpicture}
\end{document}

答案1

如上所述敲击根据他上述评论,这executes at begin cell是针对第四个(d)示例的解决方案:

\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{matrix}

\begin{document}
\begin{tikzpicture}
\matrix (d) [matrix of nodes,
             nodes={draw, minimum size=2ex},
             execute at begin cell= {|[label=\the\pgfmatrixcurrentcolumn, % <---
                                       label=left:\the\pgfmatrixcurrentrow]|} % <---
             ]
{
    D\\
};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容