# Three colors in a node Tikz

I would like a circle node split in three equal parts and colored in three different colors. Like in this link here https://fr.m.wikipedia.org/wiki/Fichier:Graph-Biconnected-Components.svg The node that is colored in blue, green and yellow. Any idea how to do it?

• The path picture will be your friend. We have some questions on this site that already have an answer to your question but I can't find them right now. Sep 15 at 10:32
• Sep 15 at 10:34
• Thanks Rmano, I think the first suggestion is better. Next I need to figure out how to make several of these and connect them with an edge. Sep 15 at 11:15
• Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.
– Community Bot
Sep 15 at 11:50

Here's an idea how we could achieve that with a path picture:

The keys node split color n can be used to change the color of the segments. (If you're using more than three you need to initialize them via node split color 4/.initial=black.)

The key node split radius is set to 1 as I'm setting up a custom coordinate system where 1 is the radius of the circular node.

For rectangle shape this is set to sqrt(2) to include all corners. (There are other ways to extend to non-circle shapes. This one distorts the angles for non-square rectangles.)

You can now place any node you want (though circle makes the most sense) and use the node split… keys to add the partitions.

I've added your example using tikzcd which uses a TikZ \matrix to place the nodes on a grid.

## Code

\documentclass[tikz,border=1mm]{standalone}
\usetikzlibrary{
calc,  % for ($<coordinate calculation>$)
cd     % for tikzcd environment
}
\tikzset{
node split color 1/.initial=red,
node split color 2/.initial=green,
node split color 3/.initial=blue,
node split half/.style={node split={#1,#1+180}},
node split/.style args={#1,#2}{
path picture={
\tikzset{
x=($(path picture bounding box.east)-(path picture bounding box.center)$),
y=($(path picture bounding box.north)-(path picture bounding box.center)$),
\foreach \ang[count=\iAng, remember=\ang as \prevAng (initially #1)] in {#2,360+#1}
\fill[line join=round, draw, fill=\pgfkeysvalueof{/tikz/node split color \iAng}]
(path picture bounding box.center)
arc[start angle=\prevAng, end angle=\ang] --cycle;
} } }
\begin{document}
\begin{tikzpicture}[
c/.style={shape=circle, draw, minimum size=1cm},
r/.style={shape=rectangle, draw, minimum width=.8cm,
minimum height=1.2cm, node split radius=sqrt 2}]

\node[c]                                                                     {};
\node[c, node split half=75]                                (one) at (1.5,0) {};
\node[c, node split={45,90,180}, node split color 1=orange] (two) at (3,  0) {};

\draw[thick] (one) -- (two);

\tikzset{yshift=-1.3cm}
\node[r]                                            {};
\node[r, node split half=75]             at (1.5,0) {};
\node[r, yellow, node split={45,90,180}] at (3,  0) {};
\end{tikzpicture}

\begin{tikzcd}[
cells={nodes={shape=circle, draw=black, minimum size=1cm}},
tikz/.code=\tikzset{#1},
tikz={
r/.style={fill=red},
g/.style={fill=green},
b/.style={fill=blue},
G/.style={fill=gray},
rc/.style={node split color 1=red, node split color 2=cyan, node split half=0},
ym/.style={node split color 1=yellow,node split color 2=magenta, node split half=-45},
ybg/.style={
node split color 1=yellow, node split color 2=blue, node split color 3=green,
node split={100,220,340}},
mc/.style={node split color 1=magenta, node split color 2=cyan, node split half=-45},
gG/.style={node split color 1=green, node split color 2=gray, node split half=-45}
},
arrows=-,
]
|[r]| \rar\dar & |[r]| \dar & |[g]| \drar\ar[rr] &                 & |[g]| \dar\ar[dl] \\
|[r]| \rar     & |[rc]|\dar &                    & |[g]| \dar      & |[g]| \dar        \\
& |[mc]|\rar & |[ym]| \rar        & |[ybg]|\dar\rar & |[gG]|\dar        \\
&            &                    & |[b]|           & |[G]|
\end{tikzcd}
\end{document}


## Output

• Very interesting. Please, could you explain the meaning of 180 in node split={45,90,180}? Sep 15 at 14:09
• @Sigur It's just the (starting) angle of the last segment. node split={45,90,180} draws circular segments between angle 45 and 90, between 90 and 180 as well as between 180 and (360+)45. Since the first angle (here 45) is special we split it off into #1 and a) use it in the remember declaration and b) move it to the back (with 360) to complete the circle. Sep 15 at 14:18

The figure is interesting. Each color corresponds to a biconnected component.

I draw with the like-node pic following (see this answer and this answer) \documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}
\def\a{.6} % size of circular vertexes
\tikzset{c/.style={circle,draw,minimum size=\a cm}}
\tikzset{one color/.style={c,fill=#1}}
\tikzset{pics/two colors/.style args=
{#1|#2|rotate=#3}{code={%
\fill[#1,rotate=#3] (0,\a/2) arc(90:270:\a/2)--cycle;
\fill[#2,rotate=#3] (0,\a/2) arc(90:-90:\a/2)--cycle;
\path (0,0) node[circle,draw,minimum size=\a cm] (-boundary) {};
}}}
\tikzset{pics/three colors/.style args=
{#1|#2|#3|rotate=#4}{code={%
\fill[#1,rotate=#4] (0,\a/2) arc(90:210:\a/2)--(0,0)--cycle;
\fill[#2,rotate=#4] (0,\a/2) arc(90:-30:\a/2)--(0,0)--cycle;
\fill[#3,rotate=#4] (210:\a/2) arc(210:330:\a/2)--(0,0)--cycle;
\path (0,0) node[c] (-boundary) {};
}}}
\path
(0,0)     node[one color=red] (R1) {}
+(-.8,.8) node[one color=red] (R2) {}
+(-1,-.5) node[one color=red] (R3) {}
(1,.2)    node[one color=green] (G1) {}
+(.8,1)   node[one color=green] (G2) {}
+(1.5,.2) node[one color=green] (G3) {}
+(3,-1)   node[one color=green] (G4) {}
+(.8,-2.2)  node[one color=blue] (B) {}
(B)+(.7,-1.2)  node[one color=gray!50] (G) {}
;
\path
(-.1,-1.5)  pic (RC) {two colors={red|cyan!50|rotate=-90}}
(.8,-2.5)   pic (CM) {two colors={cyan!50|magenta|rotate=45}}
(1,-1)      pic (MY) {two colors={magenta|yellow|rotate=45}}
(B)+(1,-.2) pic (GG) {two colors={gray|green|rotate=45}}
;
\path (B)+(.4,1.2)  pic (YGB) {three colors={yellow|green|blue|rotate=20}};

\draw (R1)--(R2)--(R3) (RC-boundary)--(CM-boundary)--
(MY-boundary)--(YGB-boundary)
(G1)--(G2)--(G3)--(G1) (G3)--(G4)
(G4)--(GG-boundary)--(G)
(RC-boundary)--(R1) (RC-boundary)--(R3);
\draw[->] (YGB-boundary)--(GG-boundary);
\draw[->] (B)--(YGB-boundary);
\draw[->] (YGB-boundary)--(G1);
\end{tikzpicture}
\end{document}