The following code draws a hypercube with labeled nodes. This is working fine so far. Now, I'd like to colour some specific nodes in a different colour.
The PGF manual says in chapter 16.14 (page 207) by using \node also
[...] most of the options will have no effect since you cannot change the appearance of the node, that is, you cannot change a red node into a green node using these “late” options. However, giving the
append after commandandprefix after commandoptions inside the late options (directly or indirectly) does have the desired effect: The given path gets executed with the\tikzlastnodeset to the determined node.
All my approaches to colour a node in blue failed though. Can someone help me with this?
Btw, I have a working solution, where I'm able to colour each node individually, because I coded the cube manually without a for loop. This question is about a solution, using a for loop to draw the cube.
MWE:
\documentclass[tikz, border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}[
line width=0.6pt,
every node/.style={circle, draw, fill, minimum size=6pt, inner sep=0pt, font=\scriptsize\bfseries}]
\pgfsetxvec{\pgfpoint{0.9cm}{0.0cm}}
\pgfsetyvec{\pgfpoint{0.0cm}{0.9cm}}
\foreach \point / \id / \angle in {
% outer cube
(0,0)/0001/270,
(0,5)/0011/90,
(5,0)/1001/270,
(5,5)/1011/90,
(2,2)/0101/180,
(2,7)/0111/90,
(7,2)/1101/270,
(7,7)/1111/90,
% inner cube
(2.5,1.5)/0000/270,
(2.5,3.5)/0010/90,
(4.5,1.5)/1000/250,
(4.5,3.5)/1010/120,
(3.5,2.5)/0100/170,
(3.5,4.5)/0110/180,
(5.5,2.5)/1100/10,
(5.5,4.5)/1110/0}
{
\node (\id) at \point [label=\angle:\id] {};
}
% Here I'd like to color specific nodes blue.
% Unfortunately this isn't working...
%
% \foreach \id in {0011, 1011}
% {
% \node also [append after command={blue}] (\id);
% }
\path
(0011) edge (1011) edge (0111) edge (0001)
(1001) edge (0001) edge (1101) edge (1011)
(1111) edge (1101) edge (1011) edge (0111)
(0010) edge (1010) edge (0110) edge (0000)
(1000) edge (0000) edge (1100) edge (1010)
(1110) edge (1100) edge (1010) edge (0110);
\path[dashed]
(0101) edge (1101) edge (0001) edge (0111)
(0100) edge (1100) edge (0000) edge (0110);
\path[dotted]
(0000) edge (0001)
(0010) edge (0011)
(0100) edge (0101)
(0110) edge (0111)
(1000) edge (1001)
(1010) edge (1011)
(1100) edge (1101)
(1110) edge (1111);
\end{tikzpicture}
\end{document}



every nodeparameter, definefill=blue. Does this help? – Someone May 25 '21 at 21:02foreach loop, like\foreach \point / \id / \angle / \colour, then add the colour of the node inside the datas? Please feel free to be more specific about what nodes you want to draw in another colour (and what colour/colours). – SebGlav May 25 '21 at 21:03'\tikzset{ 1011/.style={blue}, 0011/.style={blue} }and so on. Then modify the loop to say\node (\id) at \point [label=\angle:\id, \id/.try] {};, i.e. add, \id/.tryin the node style. – Torbjørn T. May 25 '21 at 23:16