I'd like to access the style of a node, something like mynode.fill or mynode.color etc.. Particularly, I have this task: draw a node and grid it. But I'd like to use some node properties when I plot the grid.
\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}

tikzpictures, which really should be avoided. I think you want to use alocal bounding box, orfitthe stuff. The fill color is stored in\tikz@fillcolor, and if you fill\tikz@mode@filltrueis also issued. – Jan 03 '21 at 19:45tikzway is to define a style keymy nodes/.style={color=red, ...}and then you can apply it to different nodes. For the positioning problem, you might findpgfmanual, sec. 3.4 and 3.8 helpful. – muzimuzhi Z Jan 03 '21 at 20:56