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.


\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);}}


\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!  

% 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. 


enter image description here

  • 1
    Your approach nests tikzpictures, which really should be avoided. I think you want to use a local bounding box, or fit the stuff. The fill color is stored in \tikz@fillcolor, and if you fill \tikz@mode@filltrue is also issued. – user232027 Jan 3 at 19:45
  • Retrieving option value is in general hard. You need to know the implementation of every key and take care of the grouping/scoping. The tikz way is to define a style key my nodes/.style={color=red, ...} and then you can apply it to different nodes. For the positioning problem, you might find pgfmanual, sec. 3.4 and 3.8 helpful. – muzimuzhi Z Jan 3 at 20:56
  • Thank you for your comments. Eventually, I solved the problem with pic. I think my problem question is really about how to turn a grid into a node. Pic seems to be the best choice with my limited skills in tikz. – Liping Liu Jan 4 at 4:00
  • This is the key technique I have used: tex.stackexchange.com/questions/241719/… – Liping Liu Jan 4 at 4:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.