Tree edges different coloring

Clash Royale CLAN TAG#URR8PPP
up vote
6
down vote
favorite
I want to make tree with each node has valency of three. I got the below code online somewhere. The first level has valency three however second and third level has valency four, and I also want to color the child different from parent and just want to use three colors. (e.g if parent is red then the branches will be green and blue)
documentclassminimal
usepackagetikz
usetikzlibrarytrees,snakes
begindocument
pagestyleempty
tikzstylelevel 1=[level distance= 32mm,sibling angle=120]
tikzstylelevel 2=[level distance= 16mm,sibling angle=60]
tikzstylelevel 3=[level distance = 12mm,sibling angle=30]
tikzstyleevery node=[fill]
%tikzstyleedge from parent=[segment length=1mm,
% segment angle=10,draw]
begintikzpicture[grow cyclic,shape=circle,very thick,level distance=13mm,
cap=round]
node child [color=A] foreach A in red,green,blue
node child [color=A!50!B] foreach B in red, green,blue
node child [color=A!50!B!50!C] foreach C in red,green,blue
node
;
endtikzpicture

I am new in using tikz and didn't feel comfortable in working with it so far.
tikz-pgf tikz-styles tikz-trees
add a comment |Â
up vote
6
down vote
favorite
I want to make tree with each node has valency of three. I got the below code online somewhere. The first level has valency three however second and third level has valency four, and I also want to color the child different from parent and just want to use three colors. (e.g if parent is red then the branches will be green and blue)
documentclassminimal
usepackagetikz
usetikzlibrarytrees,snakes
begindocument
pagestyleempty
tikzstylelevel 1=[level distance= 32mm,sibling angle=120]
tikzstylelevel 2=[level distance= 16mm,sibling angle=60]
tikzstylelevel 3=[level distance = 12mm,sibling angle=30]
tikzstyleevery node=[fill]
%tikzstyleedge from parent=[segment length=1mm,
% segment angle=10,draw]
begintikzpicture[grow cyclic,shape=circle,very thick,level distance=13mm,
cap=round]
node child [color=A] foreach A in red,green,blue
node child [color=A!50!B] foreach B in red, green,blue
node child [color=A!50!B!50!C] foreach C in red,green,blue
node
;
endtikzpicture

I am new in using tikz and didn't feel comfortable in working with it so far.
tikz-pgf tikz-styles tikz-trees
Please addenddocumentand usetikzset{level 1/.style=level distance= 32mm,sibling angle=120and likewise for the other styles. And please explain what "valency" means. My current interpretation suggests it is not possible to achieve this with 3 colors only if a parent has more than 2 children.
â marmot
Sep 5 at 5:50
add a comment |Â
up vote
6
down vote
favorite
up vote
6
down vote
favorite
I want to make tree with each node has valency of three. I got the below code online somewhere. The first level has valency three however second and third level has valency four, and I also want to color the child different from parent and just want to use three colors. (e.g if parent is red then the branches will be green and blue)
documentclassminimal
usepackagetikz
usetikzlibrarytrees,snakes
begindocument
pagestyleempty
tikzstylelevel 1=[level distance= 32mm,sibling angle=120]
tikzstylelevel 2=[level distance= 16mm,sibling angle=60]
tikzstylelevel 3=[level distance = 12mm,sibling angle=30]
tikzstyleevery node=[fill]
%tikzstyleedge from parent=[segment length=1mm,
% segment angle=10,draw]
begintikzpicture[grow cyclic,shape=circle,very thick,level distance=13mm,
cap=round]
node child [color=A] foreach A in red,green,blue
node child [color=A!50!B] foreach B in red, green,blue
node child [color=A!50!B!50!C] foreach C in red,green,blue
node
;
endtikzpicture

I am new in using tikz and didn't feel comfortable in working with it so far.
tikz-pgf tikz-styles tikz-trees
I want to make tree with each node has valency of three. I got the below code online somewhere. The first level has valency three however second and third level has valency four, and I also want to color the child different from parent and just want to use three colors. (e.g if parent is red then the branches will be green and blue)
documentclassminimal
usepackagetikz
usetikzlibrarytrees,snakes
begindocument
pagestyleempty
tikzstylelevel 1=[level distance= 32mm,sibling angle=120]
tikzstylelevel 2=[level distance= 16mm,sibling angle=60]
tikzstylelevel 3=[level distance = 12mm,sibling angle=30]
tikzstyleevery node=[fill]
%tikzstyleedge from parent=[segment length=1mm,
% segment angle=10,draw]
begintikzpicture[grow cyclic,shape=circle,very thick,level distance=13mm,
cap=round]
node child [color=A] foreach A in red,green,blue
node child [color=A!50!B] foreach B in red, green,blue
node child [color=A!50!B!50!C] foreach C in red,green,blue
node
;
endtikzpicture

I am new in using tikz and didn't feel comfortable in working with it so far.
tikz-pgf tikz-styles tikz-trees
tikz-pgf tikz-styles tikz-trees
edited Sep 5 at 5:47
marmot
58.3k463126
58.3k463126
asked Sep 5 at 5:39
Touseef
723
723
Please addenddocumentand usetikzset{level 1/.style=level distance= 32mm,sibling angle=120and likewise for the other styles. And please explain what "valency" means. My current interpretation suggests it is not possible to achieve this with 3 colors only if a parent has more than 2 children.
â marmot
Sep 5 at 5:50
add a comment |Â
Please addenddocumentand usetikzset{level 1/.style=level distance= 32mm,sibling angle=120and likewise for the other styles. And please explain what "valency" means. My current interpretation suggests it is not possible to achieve this with 3 colors only if a parent has more than 2 children.
â marmot
Sep 5 at 5:50
Please add
enddocument and use tikzset{level 1/.style=level distance= 32mm,sibling angle=120 and likewise for the other styles. And please explain what "valency" means. My current interpretation suggests it is not possible to achieve this with 3 colors only if a parent has more than 2 children.â marmot
Sep 5 at 5:50
Please add
enddocument and use tikzset{level 1/.style=level distance= 32mm,sibling angle=120 and likewise for the other styles. And please explain what "valency" means. My current interpretation suggests it is not possible to achieve this with 3 colors only if a parent has more than 2 children.â marmot
Sep 5 at 5:50
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
8
down vote
accepted
Very similar to Andrew's nice answer except that parents and children have different colors. EDIT: removed a superfluous index, big thanks to Andrew! @nd EDIT: Simplification with pgfkeysalso.
documentclass[tikz,border=3.14mm]standalone
usetikzlibrarytrees,snakes
begindocument
pagestyleempty
xdefmycolorblack
xdefColorList"red","green!60!black","blue"
tikzsetlevel 1/.style=level distance= 32mm,sibling angle=120,
level 2/.style=level distance= 16mm,sibling angle=60,
level 3/.style=level distance = 12mm,sibling angle=30,
every node/.append style=fill,
my color/.code=pgfmathparseColorList[mod(#1,3)]
pgfkeysalso/tikz/color/.expanded=pgfmathresult
begintikzpicture[grow cyclic,shape=circle,very thick,level distance=13mm,
cap=round]
node child [my color=A] foreach A in 0,1,2
node child [my color=A+B+1] foreach B in 0,1
node child [my color=A+B+C+2] foreach C in 0,1
node
;
endtikzpicture
enddocument

3
+1 Very cute! :) Part of me is unhappy that you are redefining theindexcommand but of course this doesn't matter since everything happens inside a group.
â Andrew
Sep 5 at 6:34
1
@Andrew Good point. Will fix it.
â marmot
Sep 5 at 6:36
add a comment |Â
up vote
6
down vote
If you want each vertex to have valence 3 then you should loop over only two colours for the child nodes. This produces:

Here is the modified code:
documentclassminimal
usepackagetikz
usetikzlibrarytrees,snakes
begindocument
pagestyleempty
tikzstylelevel 1=[level distance= 32mm,sibling angle=120]
tikzstylelevel 2=[level distance= 16mm,sibling angle=60]
tikzstylelevel 3=[level distance = 12mm,sibling angle=30]
tikzstyleevery node=[fill]
%tikzstyleedge from parent=[segment length=1mm,
% segment angle=10,draw]
begintikzpicture[grow cyclic,shape=circle,very thick,level distance=13mm,
cap=round]
node child [color=A] foreach A in red,green,blue
node child [color=A!50!B] foreach B in red, green
node child [color=A!50!B!50!C] foreach C in red,green
node
;
endtikzpicture
enddocument
Thanks @Andrew. I did this earlier myself however my problem is also colors. The red parent should not have red child directly.
â Touseef
Sep 5 at 6:31
@Touseef Sorry, didn't notice your colour requirement but marmot seems to have sorted it out.
â Andrew
Sep 5 at 6:33
Yeah he did it. I am now trying to understand his magic code lines :-)
â Touseef
Sep 5 at 6:35
@Touseef It's just a clever use of mod 3 arithmetic combined with the list of three colours defined inColorList.
â Andrew
Sep 5 at 6:38
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
8
down vote
accepted
Very similar to Andrew's nice answer except that parents and children have different colors. EDIT: removed a superfluous index, big thanks to Andrew! @nd EDIT: Simplification with pgfkeysalso.
documentclass[tikz,border=3.14mm]standalone
usetikzlibrarytrees,snakes
begindocument
pagestyleempty
xdefmycolorblack
xdefColorList"red","green!60!black","blue"
tikzsetlevel 1/.style=level distance= 32mm,sibling angle=120,
level 2/.style=level distance= 16mm,sibling angle=60,
level 3/.style=level distance = 12mm,sibling angle=30,
every node/.append style=fill,
my color/.code=pgfmathparseColorList[mod(#1,3)]
pgfkeysalso/tikz/color/.expanded=pgfmathresult
begintikzpicture[grow cyclic,shape=circle,very thick,level distance=13mm,
cap=round]
node child [my color=A] foreach A in 0,1,2
node child [my color=A+B+1] foreach B in 0,1
node child [my color=A+B+C+2] foreach C in 0,1
node
;
endtikzpicture
enddocument

3
+1 Very cute! :) Part of me is unhappy that you are redefining theindexcommand but of course this doesn't matter since everything happens inside a group.
â Andrew
Sep 5 at 6:34
1
@Andrew Good point. Will fix it.
â marmot
Sep 5 at 6:36
add a comment |Â
up vote
8
down vote
accepted
Very similar to Andrew's nice answer except that parents and children have different colors. EDIT: removed a superfluous index, big thanks to Andrew! @nd EDIT: Simplification with pgfkeysalso.
documentclass[tikz,border=3.14mm]standalone
usetikzlibrarytrees,snakes
begindocument
pagestyleempty
xdefmycolorblack
xdefColorList"red","green!60!black","blue"
tikzsetlevel 1/.style=level distance= 32mm,sibling angle=120,
level 2/.style=level distance= 16mm,sibling angle=60,
level 3/.style=level distance = 12mm,sibling angle=30,
every node/.append style=fill,
my color/.code=pgfmathparseColorList[mod(#1,3)]
pgfkeysalso/tikz/color/.expanded=pgfmathresult
begintikzpicture[grow cyclic,shape=circle,very thick,level distance=13mm,
cap=round]
node child [my color=A] foreach A in 0,1,2
node child [my color=A+B+1] foreach B in 0,1
node child [my color=A+B+C+2] foreach C in 0,1
node
;
endtikzpicture
enddocument

3
+1 Very cute! :) Part of me is unhappy that you are redefining theindexcommand but of course this doesn't matter since everything happens inside a group.
â Andrew
Sep 5 at 6:34
1
@Andrew Good point. Will fix it.
â marmot
Sep 5 at 6:36
add a comment |Â
up vote
8
down vote
accepted
up vote
8
down vote
accepted
Very similar to Andrew's nice answer except that parents and children have different colors. EDIT: removed a superfluous index, big thanks to Andrew! @nd EDIT: Simplification with pgfkeysalso.
documentclass[tikz,border=3.14mm]standalone
usetikzlibrarytrees,snakes
begindocument
pagestyleempty
xdefmycolorblack
xdefColorList"red","green!60!black","blue"
tikzsetlevel 1/.style=level distance= 32mm,sibling angle=120,
level 2/.style=level distance= 16mm,sibling angle=60,
level 3/.style=level distance = 12mm,sibling angle=30,
every node/.append style=fill,
my color/.code=pgfmathparseColorList[mod(#1,3)]
pgfkeysalso/tikz/color/.expanded=pgfmathresult
begintikzpicture[grow cyclic,shape=circle,very thick,level distance=13mm,
cap=round]
node child [my color=A] foreach A in 0,1,2
node child [my color=A+B+1] foreach B in 0,1
node child [my color=A+B+C+2] foreach C in 0,1
node
;
endtikzpicture
enddocument

Very similar to Andrew's nice answer except that parents and children have different colors. EDIT: removed a superfluous index, big thanks to Andrew! @nd EDIT: Simplification with pgfkeysalso.
documentclass[tikz,border=3.14mm]standalone
usetikzlibrarytrees,snakes
begindocument
pagestyleempty
xdefmycolorblack
xdefColorList"red","green!60!black","blue"
tikzsetlevel 1/.style=level distance= 32mm,sibling angle=120,
level 2/.style=level distance= 16mm,sibling angle=60,
level 3/.style=level distance = 12mm,sibling angle=30,
every node/.append style=fill,
my color/.code=pgfmathparseColorList[mod(#1,3)]
pgfkeysalso/tikz/color/.expanded=pgfmathresult
begintikzpicture[grow cyclic,shape=circle,very thick,level distance=13mm,
cap=round]
node child [my color=A] foreach A in 0,1,2
node child [my color=A+B+1] foreach B in 0,1
node child [my color=A+B+C+2] foreach C in 0,1
node
;
endtikzpicture
enddocument

edited Sep 5 at 7:33
answered Sep 5 at 6:22
marmot
58.3k463126
58.3k463126
3
+1 Very cute! :) Part of me is unhappy that you are redefining theindexcommand but of course this doesn't matter since everything happens inside a group.
â Andrew
Sep 5 at 6:34
1
@Andrew Good point. Will fix it.
â marmot
Sep 5 at 6:36
add a comment |Â
3
+1 Very cute! :) Part of me is unhappy that you are redefining theindexcommand but of course this doesn't matter since everything happens inside a group.
â Andrew
Sep 5 at 6:34
1
@Andrew Good point. Will fix it.
â marmot
Sep 5 at 6:36
3
3
+1 Very cute! :) Part of me is unhappy that you are redefining the
index command but of course this doesn't matter since everything happens inside a group.â Andrew
Sep 5 at 6:34
+1 Very cute! :) Part of me is unhappy that you are redefining the
index command but of course this doesn't matter since everything happens inside a group.â Andrew
Sep 5 at 6:34
1
1
@Andrew Good point. Will fix it.
â marmot
Sep 5 at 6:36
@Andrew Good point. Will fix it.
â marmot
Sep 5 at 6:36
add a comment |Â
up vote
6
down vote
If you want each vertex to have valence 3 then you should loop over only two colours for the child nodes. This produces:

Here is the modified code:
documentclassminimal
usepackagetikz
usetikzlibrarytrees,snakes
begindocument
pagestyleempty
tikzstylelevel 1=[level distance= 32mm,sibling angle=120]
tikzstylelevel 2=[level distance= 16mm,sibling angle=60]
tikzstylelevel 3=[level distance = 12mm,sibling angle=30]
tikzstyleevery node=[fill]
%tikzstyleedge from parent=[segment length=1mm,
% segment angle=10,draw]
begintikzpicture[grow cyclic,shape=circle,very thick,level distance=13mm,
cap=round]
node child [color=A] foreach A in red,green,blue
node child [color=A!50!B] foreach B in red, green
node child [color=A!50!B!50!C] foreach C in red,green
node
;
endtikzpicture
enddocument
Thanks @Andrew. I did this earlier myself however my problem is also colors. The red parent should not have red child directly.
â Touseef
Sep 5 at 6:31
@Touseef Sorry, didn't notice your colour requirement but marmot seems to have sorted it out.
â Andrew
Sep 5 at 6:33
Yeah he did it. I am now trying to understand his magic code lines :-)
â Touseef
Sep 5 at 6:35
@Touseef It's just a clever use of mod 3 arithmetic combined with the list of three colours defined inColorList.
â Andrew
Sep 5 at 6:38
add a comment |Â
up vote
6
down vote
If you want each vertex to have valence 3 then you should loop over only two colours for the child nodes. This produces:

Here is the modified code:
documentclassminimal
usepackagetikz
usetikzlibrarytrees,snakes
begindocument
pagestyleempty
tikzstylelevel 1=[level distance= 32mm,sibling angle=120]
tikzstylelevel 2=[level distance= 16mm,sibling angle=60]
tikzstylelevel 3=[level distance = 12mm,sibling angle=30]
tikzstyleevery node=[fill]
%tikzstyleedge from parent=[segment length=1mm,
% segment angle=10,draw]
begintikzpicture[grow cyclic,shape=circle,very thick,level distance=13mm,
cap=round]
node child [color=A] foreach A in red,green,blue
node child [color=A!50!B] foreach B in red, green
node child [color=A!50!B!50!C] foreach C in red,green
node
;
endtikzpicture
enddocument
Thanks @Andrew. I did this earlier myself however my problem is also colors. The red parent should not have red child directly.
â Touseef
Sep 5 at 6:31
@Touseef Sorry, didn't notice your colour requirement but marmot seems to have sorted it out.
â Andrew
Sep 5 at 6:33
Yeah he did it. I am now trying to understand his magic code lines :-)
â Touseef
Sep 5 at 6:35
@Touseef It's just a clever use of mod 3 arithmetic combined with the list of three colours defined inColorList.
â Andrew
Sep 5 at 6:38
add a comment |Â
up vote
6
down vote
up vote
6
down vote
If you want each vertex to have valence 3 then you should loop over only two colours for the child nodes. This produces:

Here is the modified code:
documentclassminimal
usepackagetikz
usetikzlibrarytrees,snakes
begindocument
pagestyleempty
tikzstylelevel 1=[level distance= 32mm,sibling angle=120]
tikzstylelevel 2=[level distance= 16mm,sibling angle=60]
tikzstylelevel 3=[level distance = 12mm,sibling angle=30]
tikzstyleevery node=[fill]
%tikzstyleedge from parent=[segment length=1mm,
% segment angle=10,draw]
begintikzpicture[grow cyclic,shape=circle,very thick,level distance=13mm,
cap=round]
node child [color=A] foreach A in red,green,blue
node child [color=A!50!B] foreach B in red, green
node child [color=A!50!B!50!C] foreach C in red,green
node
;
endtikzpicture
enddocument
If you want each vertex to have valence 3 then you should loop over only two colours for the child nodes. This produces:

Here is the modified code:
documentclassminimal
usepackagetikz
usetikzlibrarytrees,snakes
begindocument
pagestyleempty
tikzstylelevel 1=[level distance= 32mm,sibling angle=120]
tikzstylelevel 2=[level distance= 16mm,sibling angle=60]
tikzstylelevel 3=[level distance = 12mm,sibling angle=30]
tikzstyleevery node=[fill]
%tikzstyleedge from parent=[segment length=1mm,
% segment angle=10,draw]
begintikzpicture[grow cyclic,shape=circle,very thick,level distance=13mm,
cap=round]
node child [color=A] foreach A in red,green,blue
node child [color=A!50!B] foreach B in red, green
node child [color=A!50!B!50!C] foreach C in red,green
node
;
endtikzpicture
enddocument
answered Sep 5 at 6:15
Andrew
27.4k34075
27.4k34075
Thanks @Andrew. I did this earlier myself however my problem is also colors. The red parent should not have red child directly.
â Touseef
Sep 5 at 6:31
@Touseef Sorry, didn't notice your colour requirement but marmot seems to have sorted it out.
â Andrew
Sep 5 at 6:33
Yeah he did it. I am now trying to understand his magic code lines :-)
â Touseef
Sep 5 at 6:35
@Touseef It's just a clever use of mod 3 arithmetic combined with the list of three colours defined inColorList.
â Andrew
Sep 5 at 6:38
add a comment |Â
Thanks @Andrew. I did this earlier myself however my problem is also colors. The red parent should not have red child directly.
â Touseef
Sep 5 at 6:31
@Touseef Sorry, didn't notice your colour requirement but marmot seems to have sorted it out.
â Andrew
Sep 5 at 6:33
Yeah he did it. I am now trying to understand his magic code lines :-)
â Touseef
Sep 5 at 6:35
@Touseef It's just a clever use of mod 3 arithmetic combined with the list of three colours defined inColorList.
â Andrew
Sep 5 at 6:38
Thanks @Andrew. I did this earlier myself however my problem is also colors. The red parent should not have red child directly.
â Touseef
Sep 5 at 6:31
Thanks @Andrew. I did this earlier myself however my problem is also colors. The red parent should not have red child directly.
â Touseef
Sep 5 at 6:31
@Touseef Sorry, didn't notice your colour requirement but marmot seems to have sorted it out.
â Andrew
Sep 5 at 6:33
@Touseef Sorry, didn't notice your colour requirement but marmot seems to have sorted it out.
â Andrew
Sep 5 at 6:33
Yeah he did it. I am now trying to understand his magic code lines :-)
â Touseef
Sep 5 at 6:35
Yeah he did it. I am now trying to understand his magic code lines :-)
â Touseef
Sep 5 at 6:35
@Touseef It's just a clever use of mod 3 arithmetic combined with the list of three colours defined in
ColorList.â Andrew
Sep 5 at 6:38
@Touseef It's just a clever use of mod 3 arithmetic combined with the list of three colours defined in
ColorList.â Andrew
Sep 5 at 6:38
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f449383%2ftree-edges-different-coloring%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Please add
enddocumentand usetikzset{level 1/.style=level distance= 32mm,sibling angle=120and likewise for the other styles. And please explain what "valency" means. My current interpretation suggests it is not possible to achieve this with 3 colors only if a parent has more than 2 children.â marmot
Sep 5 at 5:50