如何访问节点的样式值

如何访问节点的样式值

我想访问节点的样式,例如mynode.fillmynode.color等。具体来说,我有这个任务:绘制一个节点并对其进行网格化。但我想在绘制网格时使用一些节点属性。

\documentclass[tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{chains,shapes.geometric,arrows,calc}

\begin{document}
\newcommand{\gridnode}[3]{\draw[color=#3, step=#2] (#1.south east)  grid (#1.north west);}
\newcommand{\gridinnode}[3]{\tikz{\draw[color=#3, step=#2] (#1.south east)  grid (#1.north west);}}

\begin{tikzpicture}

\draw[draw=none, fill=white] (-4cm, -2cm) rectangle (4cm, 2cm);

\node[rectangle, color=red, inner sep=0, minimum height=2cm, minimum width=3cm, fill=black!20] (mynode) at (0, 0)
{
    % Anything like this one that works would be neat!  
    %\gridinnode{mynode}{1cm}{red};
};

% Can I access the color of mynode by using mynode instead of passing in this value?
% BTW: how to align the grid with the node? I don't like to do a lot of calculation. 
\gridnode{mynode}{1cm}{red};

\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容