Tree edges different coloring

The name of the pictureThe name of the pictureThe name of the pictureClash 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


enter image description here



I am new in using tikz and didn't feel comfortable in working with it so far.










share|improve this question























  • 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















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


enter image description here



I am new in using tikz and didn't feel comfortable in working with it so far.










share|improve this question























  • 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













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


enter image description here



I am new in using tikz and didn't feel comfortable in working with it so far.










share|improve this question















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


enter image description here



I am new in using tikz and didn't feel comfortable in working with it so far.







tikz-pgf tikz-styles tikz-trees






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 5 at 5:47









marmot

58.3k463126




58.3k463126










asked Sep 5 at 5:39









Touseef

723




723











  • 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
















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











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


enter image description here






share|improve this answer


















  • 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




    @Andrew Good point. Will fix it.
    – marmot
    Sep 5 at 6:36

















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:



enter image description here



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





share|improve this answer




















  • 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 in ColorList.
    – Andrew
    Sep 5 at 6:38











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "85"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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






























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


enter image description here






share|improve this answer


















  • 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




    @Andrew Good point. Will fix it.
    – marmot
    Sep 5 at 6:36














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


enter image description here






share|improve this answer


















  • 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




    @Andrew Good point. Will fix it.
    – marmot
    Sep 5 at 6:36












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


enter image description here






share|improve this answer














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


enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








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 the index command 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




    +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




    @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










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:



enter image description here



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





share|improve this answer




















  • 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 in ColorList.
    – Andrew
    Sep 5 at 6:38















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:



enter image description here



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





share|improve this answer




















  • 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 in ColorList.
    – Andrew
    Sep 5 at 6:38













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:



enter image description here



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





share|improve this answer












If you want each vertex to have valence 3 then you should loop over only two colours for the child nodes. This produces:



enter image description here



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






share|improve this answer












share|improve this answer



share|improve this answer










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 in ColorList.
    – 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










  • @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 in ColorList.
    – 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


















 

draft saved


draft discarded















































 


draft saved


draft discarded














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













































































這個網誌中的熱門文章

tkz-euclide: tkzDrawCircle[R] not working

How to combine Bézier curves to a surface?

1st Magritte Awards