How to compute the *key* of a pgfkeyssetvalue command?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
5
down vote

favorite












I have a list of (angles/value) pairs. I'd like to use TikZ to



  1. draw nodes with those values at these angles (easy),

  2. then draw an edge from node i to i+1, with the value of node i as a label (not at all easy).

My idea so far: store the values in pgfkeys, with keys the same as the node names. Then, values could be easily accessed. Problem is, I cannot get the pgfkeyssetvalue to evalute the node name first.



Example:



documentclass[tikz]standalone

usepackagetikz

begindocument

begintikzpicture
draw [dotted] (0,0) circle (2cm);

% draw nodes on a circle, remembering their value fails:
foreach angle/value [count = i] in 0/17, 45/22, 80/5, 140/12
node [circle, draw, fill=white] (pi) at (angle:2cm) value;
pgfkeyssetvalue/nodevalues/pivalue


% to illustrate that it works with explicit node names:
pgfkeyssetvalue/nodevalues/p117
pgfkeyssetvalue/nodevalues/p222

% edges:
foreach [evaluate = j=int(mod(i, 4)+1)] i in 1,...,4
draw [->] (pi) to [bend right=45] node[midway] pgfkeysvalueof/nodevalues/pi (pj) ;
endtikzpicture

enddocument


This draws the edges for the manually set keys /nodevalues/p1 and /nodevalues/p2 correctly. But pgfkeyssetkeys does not do what I like. Expected result would be that 5->12 arc is label with 5, and 12->17 with 12.



Example ring with two missing labels







share|improve this question






















  • Are you by chance looking for an array? BTW, the node names can be numbers, so you could just give the nodes the same names as their contents.
    – marmot
    Aug 21 at 15:50










  • Numbers or pi makes no difference in MWE. Node names are actually not explicitly used in the keys; could be arbitrary; just the same for convenience. Not sure what you have in mind with array?
    – Holger Karl
    Aug 21 at 15:52











  • I use an array in my answer below. BTW Welcome to TeX.SE!
    – marmot
    Aug 21 at 16:01














up vote
5
down vote

favorite












I have a list of (angles/value) pairs. I'd like to use TikZ to



  1. draw nodes with those values at these angles (easy),

  2. then draw an edge from node i to i+1, with the value of node i as a label (not at all easy).

My idea so far: store the values in pgfkeys, with keys the same as the node names. Then, values could be easily accessed. Problem is, I cannot get the pgfkeyssetvalue to evalute the node name first.



Example:



documentclass[tikz]standalone

usepackagetikz

begindocument

begintikzpicture
draw [dotted] (0,0) circle (2cm);

% draw nodes on a circle, remembering their value fails:
foreach angle/value [count = i] in 0/17, 45/22, 80/5, 140/12
node [circle, draw, fill=white] (pi) at (angle:2cm) value;
pgfkeyssetvalue/nodevalues/pivalue


% to illustrate that it works with explicit node names:
pgfkeyssetvalue/nodevalues/p117
pgfkeyssetvalue/nodevalues/p222

% edges:
foreach [evaluate = j=int(mod(i, 4)+1)] i in 1,...,4
draw [->] (pi) to [bend right=45] node[midway] pgfkeysvalueof/nodevalues/pi (pj) ;
endtikzpicture

enddocument


This draws the edges for the manually set keys /nodevalues/p1 and /nodevalues/p2 correctly. But pgfkeyssetkeys does not do what I like. Expected result would be that 5->12 arc is label with 5, and 12->17 with 12.



Example ring with two missing labels







share|improve this question






















  • Are you by chance looking for an array? BTW, the node names can be numbers, so you could just give the nodes the same names as their contents.
    – marmot
    Aug 21 at 15:50










  • Numbers or pi makes no difference in MWE. Node names are actually not explicitly used in the keys; could be arbitrary; just the same for convenience. Not sure what you have in mind with array?
    – Holger Karl
    Aug 21 at 15:52











  • I use an array in my answer below. BTW Welcome to TeX.SE!
    – marmot
    Aug 21 at 16:01












up vote
5
down vote

favorite









up vote
5
down vote

favorite











I have a list of (angles/value) pairs. I'd like to use TikZ to



  1. draw nodes with those values at these angles (easy),

  2. then draw an edge from node i to i+1, with the value of node i as a label (not at all easy).

My idea so far: store the values in pgfkeys, with keys the same as the node names. Then, values could be easily accessed. Problem is, I cannot get the pgfkeyssetvalue to evalute the node name first.



Example:



documentclass[tikz]standalone

usepackagetikz

begindocument

begintikzpicture
draw [dotted] (0,0) circle (2cm);

% draw nodes on a circle, remembering their value fails:
foreach angle/value [count = i] in 0/17, 45/22, 80/5, 140/12
node [circle, draw, fill=white] (pi) at (angle:2cm) value;
pgfkeyssetvalue/nodevalues/pivalue


% to illustrate that it works with explicit node names:
pgfkeyssetvalue/nodevalues/p117
pgfkeyssetvalue/nodevalues/p222

% edges:
foreach [evaluate = j=int(mod(i, 4)+1)] i in 1,...,4
draw [->] (pi) to [bend right=45] node[midway] pgfkeysvalueof/nodevalues/pi (pj) ;
endtikzpicture

enddocument


This draws the edges for the manually set keys /nodevalues/p1 and /nodevalues/p2 correctly. But pgfkeyssetkeys does not do what I like. Expected result would be that 5->12 arc is label with 5, and 12->17 with 12.



Example ring with two missing labels







share|improve this question














I have a list of (angles/value) pairs. I'd like to use TikZ to



  1. draw nodes with those values at these angles (easy),

  2. then draw an edge from node i to i+1, with the value of node i as a label (not at all easy).

My idea so far: store the values in pgfkeys, with keys the same as the node names. Then, values could be easily accessed. Problem is, I cannot get the pgfkeyssetvalue to evalute the node name first.



Example:



documentclass[tikz]standalone

usepackagetikz

begindocument

begintikzpicture
draw [dotted] (0,0) circle (2cm);

% draw nodes on a circle, remembering their value fails:
foreach angle/value [count = i] in 0/17, 45/22, 80/5, 140/12
node [circle, draw, fill=white] (pi) at (angle:2cm) value;
pgfkeyssetvalue/nodevalues/pivalue


% to illustrate that it works with explicit node names:
pgfkeyssetvalue/nodevalues/p117
pgfkeyssetvalue/nodevalues/p222

% edges:
foreach [evaluate = j=int(mod(i, 4)+1)] i in 1,...,4
draw [->] (pi) to [bend right=45] node[midway] pgfkeysvalueof/nodevalues/pi (pj) ;
endtikzpicture

enddocument


This draws the edges for the manually set keys /nodevalues/p1 and /nodevalues/p2 correctly. But pgfkeyssetkeys does not do what I like. Expected result would be that 5->12 arc is label with 5, and 12->17 with 12.



Example ring with two missing labels









share|improve this question













share|improve this question




share|improve this question








edited Aug 21 at 16:50









AndréC

2,872728




2,872728










asked Aug 21 at 15:46









Holger Karl

354




354











  • Are you by chance looking for an array? BTW, the node names can be numbers, so you could just give the nodes the same names as their contents.
    – marmot
    Aug 21 at 15:50










  • Numbers or pi makes no difference in MWE. Node names are actually not explicitly used in the keys; could be arbitrary; just the same for convenience. Not sure what you have in mind with array?
    – Holger Karl
    Aug 21 at 15:52











  • I use an array in my answer below. BTW Welcome to TeX.SE!
    – marmot
    Aug 21 at 16:01
















  • Are you by chance looking for an array? BTW, the node names can be numbers, so you could just give the nodes the same names as their contents.
    – marmot
    Aug 21 at 15:50










  • Numbers or pi makes no difference in MWE. Node names are actually not explicitly used in the keys; could be arbitrary; just the same for convenience. Not sure what you have in mind with array?
    – Holger Karl
    Aug 21 at 15:52











  • I use an array in my answer below. BTW Welcome to TeX.SE!
    – marmot
    Aug 21 at 16:01















Are you by chance looking for an array? BTW, the node names can be numbers, so you could just give the nodes the same names as their contents.
– marmot
Aug 21 at 15:50




Are you by chance looking for an array? BTW, the node names can be numbers, so you could just give the nodes the same names as their contents.
– marmot
Aug 21 at 15:50












Numbers or pi makes no difference in MWE. Node names are actually not explicitly used in the keys; could be arbitrary; just the same for convenience. Not sure what you have in mind with array?
– Holger Karl
Aug 21 at 15:52





Numbers or pi makes no difference in MWE. Node names are actually not explicitly used in the keys; could be arbitrary; just the same for convenience. Not sure what you have in mind with array?
– Holger Karl
Aug 21 at 15:52













I use an array in my answer below. BTW Welcome to TeX.SE!
– marmot
Aug 21 at 16:01




I use an array in my answer below. BTW Welcome to TeX.SE!
– marmot
Aug 21 at 16:01










3 Answers
3






active

oldest

votes

















up vote
6
down vote



accepted










Here is how I would do it: build up a list and reuse its entries.



documentclass[tikz,border=3.14mm]standalone
begindocument
begintikzpicture
draw [dotted] (0,0) circle (2cm);
% draw nodes on a circle, remembering their value no longer fails:
foreach angle/value [count = i] in 0/17, 45/22, 80/5, 140/12
node [circle, draw, fill=white] (pi) at (angle:2cm) value;
ifnumi=1
xdefLstvalue
else
xdefLstLst,value
fi

% edges:
foreach [evaluate = j=int(mod(i, 4)+1)] i in 1,...,4
pgfmathsetmacroXLst[i-1]
typeoutX
draw [->] (pi) to [bend right=45] node[midway,auto,swap]
X (pj) ;
endtikzpicture
enddocument


enter image description here



EDIT: I think this is a nice question which also deserves an explanation why it fails. Essentially the loop does the keys locally, and you need to make them global. This globalization has been achieved by @percusse in this nice answer. Once one employs it, your original approach can also be made work.



documentclass[tikz,border=3.14mm]standalone
begindocument
begintikzpicture
draw [dotted] (0,0) circle (2cm);

% draw nodes on a circle, remembering their value no longer fails:
foreach angle/value [count = i] in 0/17, 45/22, 80/5, 140/12
node [circle, draw, fill=white] (pi) at (angle:2cm) value;
begingroupglobaldefs=1relax
edeftempnoexpandpgfkeyssetvalue/nodevalues/pivalue
temp
endgroup


% edges:
foreach [evaluate = j=int(mod(i, 4)+1)] i in 1,...,4
draw [->] (pi) to [bend right=45] node[midway] pgfkeysvalueof/nodevalues/pi (pj) ;
endtikzpicture
enddocument


enter image description here



Yet another possibility would be to employ Henri Menke's trick to remember node contents, I'd be happy to spell that out if you ask me to.






share|improve this answer






















  • Nifty! Thanks a lot, that does it!
    – Holger Karl
    Aug 21 at 16:01










  • marmot: Your edited answer is enlightening, thanks. I had seen @percusse comment in the other thread, but hadn't understood its relevance here. A bit counterintuitive to have to use noexpand to expand i, though :-). The approach via macro seems quite heavy-weight?
    – Holger Karl
    Aug 22 at 6:30










  • @HolgerKarl This expansion thingy is something that one has sometimes to do in foreach loops and more often in pgfplots. It ensures here that when pgfkeyssetvalue gets "executed" i and value are already expanded. Whether or not this is "heavy weight" is a matter of taste. If you look into the codes in packages, you will often see tons of expanafter and noexpand statements. But yes, it is "nicer" if one can do without those. ;-)
    – marmot
    Aug 22 at 10:11

















up vote
4
down vote













Just for fun, a single foreach that does what you want.



documentclass[tikz,margin=2mm]standalone

usepackagetikz

begindocument

begintikzpicture
draw [dotted] (0,0) circle (2cm);

foreach angle/value [count = i, count=j from 0, remember=value as oldvalue] in 0/17, 45/22, 80/5, 140/12
node [circle, draw, fill=white] (pi) at (angle:2cm) value;
ifnumj>0
draw[->] (pj) to [bend right=45] node[midway,auto,swap] oldvalue (pi);
fi
ifnumi=4
draw[->] (pi) to [bend right=45] node[midway,auto,swap] value (p1);
fi

endtikzpicture

enddocument


enter image description here






share|improve this answer
















  • 1




    Oops, I spent the evening looking to do like you and you were faster. I had not thought at all to use two different counts, one starting at 0, the other at 1, your solution is more beautiful than mine :)
    – AndréC
    Aug 21 at 21:16







  • 1




    @AndréC Thanks! I think your remember=i as lasti (initially 4) is also very clever, saves you to do the int(mod(...)) stuff. I will try to remember that :)
    – Max
    Aug 22 at 6:19






  • 1




    Unfortunately, a single loop does not work for me - I am drawing the base graph and then different annotations on top of it (not shown in my question). But yes, that is also nice with the lasti - didnt know about that either :-)
    – Holger Karl
    Aug 22 at 6:26

















up vote
1
down vote













It is possible to solve your problem without using pgf keys but only using the native capabilities of foreach operation.



Here, I used a first loop to draw the nodes and a second to create the arrows between the nodes with the edge operation



documentclass[tikz]standalone

begindocument
begintikzpicture
draw [dotted] (0,0) circle (2cm);

% create the node
foreach angle/value [count=i,remember=angle as lastangle (initially 140),remember=i as lasti (initially 4)] in 0/17, 45/22, 80/5, 140/12
node (i) at (angle:2cm) value;

% draw arrow with edge operation
foreach value [count=i,remember =i as lasti (initially 4),remember=value as lvalue (initially 12)] in 17,22,5,12
path[->](lasti) edge[bend right=45] node[midway,auto,swap]lvalue(i);

endtikzpicture

enddocument


noeuds






share|improve this answer


















  • 1




    See above; answer to @Max
    – Holger Karl
    Aug 22 at 6:26










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%2f447009%2fhow-to-compute-the-key-of-a-pgfkeyssetvalue-command%23new-answer', 'question_page');

);

Post as a guest






























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
6
down vote



accepted










Here is how I would do it: build up a list and reuse its entries.



documentclass[tikz,border=3.14mm]standalone
begindocument
begintikzpicture
draw [dotted] (0,0) circle (2cm);
% draw nodes on a circle, remembering their value no longer fails:
foreach angle/value [count = i] in 0/17, 45/22, 80/5, 140/12
node [circle, draw, fill=white] (pi) at (angle:2cm) value;
ifnumi=1
xdefLstvalue
else
xdefLstLst,value
fi

% edges:
foreach [evaluate = j=int(mod(i, 4)+1)] i in 1,...,4
pgfmathsetmacroXLst[i-1]
typeoutX
draw [->] (pi) to [bend right=45] node[midway,auto,swap]
X (pj) ;
endtikzpicture
enddocument


enter image description here



EDIT: I think this is a nice question which also deserves an explanation why it fails. Essentially the loop does the keys locally, and you need to make them global. This globalization has been achieved by @percusse in this nice answer. Once one employs it, your original approach can also be made work.



documentclass[tikz,border=3.14mm]standalone
begindocument
begintikzpicture
draw [dotted] (0,0) circle (2cm);

% draw nodes on a circle, remembering their value no longer fails:
foreach angle/value [count = i] in 0/17, 45/22, 80/5, 140/12
node [circle, draw, fill=white] (pi) at (angle:2cm) value;
begingroupglobaldefs=1relax
edeftempnoexpandpgfkeyssetvalue/nodevalues/pivalue
temp
endgroup


% edges:
foreach [evaluate = j=int(mod(i, 4)+1)] i in 1,...,4
draw [->] (pi) to [bend right=45] node[midway] pgfkeysvalueof/nodevalues/pi (pj) ;
endtikzpicture
enddocument


enter image description here



Yet another possibility would be to employ Henri Menke's trick to remember node contents, I'd be happy to spell that out if you ask me to.






share|improve this answer






















  • Nifty! Thanks a lot, that does it!
    – Holger Karl
    Aug 21 at 16:01










  • marmot: Your edited answer is enlightening, thanks. I had seen @percusse comment in the other thread, but hadn't understood its relevance here. A bit counterintuitive to have to use noexpand to expand i, though :-). The approach via macro seems quite heavy-weight?
    – Holger Karl
    Aug 22 at 6:30










  • @HolgerKarl This expansion thingy is something that one has sometimes to do in foreach loops and more often in pgfplots. It ensures here that when pgfkeyssetvalue gets "executed" i and value are already expanded. Whether or not this is "heavy weight" is a matter of taste. If you look into the codes in packages, you will often see tons of expanafter and noexpand statements. But yes, it is "nicer" if one can do without those. ;-)
    – marmot
    Aug 22 at 10:11














up vote
6
down vote



accepted










Here is how I would do it: build up a list and reuse its entries.



documentclass[tikz,border=3.14mm]standalone
begindocument
begintikzpicture
draw [dotted] (0,0) circle (2cm);
% draw nodes on a circle, remembering their value no longer fails:
foreach angle/value [count = i] in 0/17, 45/22, 80/5, 140/12
node [circle, draw, fill=white] (pi) at (angle:2cm) value;
ifnumi=1
xdefLstvalue
else
xdefLstLst,value
fi

% edges:
foreach [evaluate = j=int(mod(i, 4)+1)] i in 1,...,4
pgfmathsetmacroXLst[i-1]
typeoutX
draw [->] (pi) to [bend right=45] node[midway,auto,swap]
X (pj) ;
endtikzpicture
enddocument


enter image description here



EDIT: I think this is a nice question which also deserves an explanation why it fails. Essentially the loop does the keys locally, and you need to make them global. This globalization has been achieved by @percusse in this nice answer. Once one employs it, your original approach can also be made work.



documentclass[tikz,border=3.14mm]standalone
begindocument
begintikzpicture
draw [dotted] (0,0) circle (2cm);

% draw nodes on a circle, remembering their value no longer fails:
foreach angle/value [count = i] in 0/17, 45/22, 80/5, 140/12
node [circle, draw, fill=white] (pi) at (angle:2cm) value;
begingroupglobaldefs=1relax
edeftempnoexpandpgfkeyssetvalue/nodevalues/pivalue
temp
endgroup


% edges:
foreach [evaluate = j=int(mod(i, 4)+1)] i in 1,...,4
draw [->] (pi) to [bend right=45] node[midway] pgfkeysvalueof/nodevalues/pi (pj) ;
endtikzpicture
enddocument


enter image description here



Yet another possibility would be to employ Henri Menke's trick to remember node contents, I'd be happy to spell that out if you ask me to.






share|improve this answer






















  • Nifty! Thanks a lot, that does it!
    – Holger Karl
    Aug 21 at 16:01










  • marmot: Your edited answer is enlightening, thanks. I had seen @percusse comment in the other thread, but hadn't understood its relevance here. A bit counterintuitive to have to use noexpand to expand i, though :-). The approach via macro seems quite heavy-weight?
    – Holger Karl
    Aug 22 at 6:30










  • @HolgerKarl This expansion thingy is something that one has sometimes to do in foreach loops and more often in pgfplots. It ensures here that when pgfkeyssetvalue gets "executed" i and value are already expanded. Whether or not this is "heavy weight" is a matter of taste. If you look into the codes in packages, you will often see tons of expanafter and noexpand statements. But yes, it is "nicer" if one can do without those. ;-)
    – marmot
    Aug 22 at 10:11












up vote
6
down vote



accepted







up vote
6
down vote



accepted






Here is how I would do it: build up a list and reuse its entries.



documentclass[tikz,border=3.14mm]standalone
begindocument
begintikzpicture
draw [dotted] (0,0) circle (2cm);
% draw nodes on a circle, remembering their value no longer fails:
foreach angle/value [count = i] in 0/17, 45/22, 80/5, 140/12
node [circle, draw, fill=white] (pi) at (angle:2cm) value;
ifnumi=1
xdefLstvalue
else
xdefLstLst,value
fi

% edges:
foreach [evaluate = j=int(mod(i, 4)+1)] i in 1,...,4
pgfmathsetmacroXLst[i-1]
typeoutX
draw [->] (pi) to [bend right=45] node[midway,auto,swap]
X (pj) ;
endtikzpicture
enddocument


enter image description here



EDIT: I think this is a nice question which also deserves an explanation why it fails. Essentially the loop does the keys locally, and you need to make them global. This globalization has been achieved by @percusse in this nice answer. Once one employs it, your original approach can also be made work.



documentclass[tikz,border=3.14mm]standalone
begindocument
begintikzpicture
draw [dotted] (0,0) circle (2cm);

% draw nodes on a circle, remembering their value no longer fails:
foreach angle/value [count = i] in 0/17, 45/22, 80/5, 140/12
node [circle, draw, fill=white] (pi) at (angle:2cm) value;
begingroupglobaldefs=1relax
edeftempnoexpandpgfkeyssetvalue/nodevalues/pivalue
temp
endgroup


% edges:
foreach [evaluate = j=int(mod(i, 4)+1)] i in 1,...,4
draw [->] (pi) to [bend right=45] node[midway] pgfkeysvalueof/nodevalues/pi (pj) ;
endtikzpicture
enddocument


enter image description here



Yet another possibility would be to employ Henri Menke's trick to remember node contents, I'd be happy to spell that out if you ask me to.






share|improve this answer














Here is how I would do it: build up a list and reuse its entries.



documentclass[tikz,border=3.14mm]standalone
begindocument
begintikzpicture
draw [dotted] (0,0) circle (2cm);
% draw nodes on a circle, remembering their value no longer fails:
foreach angle/value [count = i] in 0/17, 45/22, 80/5, 140/12
node [circle, draw, fill=white] (pi) at (angle:2cm) value;
ifnumi=1
xdefLstvalue
else
xdefLstLst,value
fi

% edges:
foreach [evaluate = j=int(mod(i, 4)+1)] i in 1,...,4
pgfmathsetmacroXLst[i-1]
typeoutX
draw [->] (pi) to [bend right=45] node[midway,auto,swap]
X (pj) ;
endtikzpicture
enddocument


enter image description here



EDIT: I think this is a nice question which also deserves an explanation why it fails. Essentially the loop does the keys locally, and you need to make them global. This globalization has been achieved by @percusse in this nice answer. Once one employs it, your original approach can also be made work.



documentclass[tikz,border=3.14mm]standalone
begindocument
begintikzpicture
draw [dotted] (0,0) circle (2cm);

% draw nodes on a circle, remembering their value no longer fails:
foreach angle/value [count = i] in 0/17, 45/22, 80/5, 140/12
node [circle, draw, fill=white] (pi) at (angle:2cm) value;
begingroupglobaldefs=1relax
edeftempnoexpandpgfkeyssetvalue/nodevalues/pivalue
temp
endgroup


% edges:
foreach [evaluate = j=int(mod(i, 4)+1)] i in 1,...,4
draw [->] (pi) to [bend right=45] node[midway] pgfkeysvalueof/nodevalues/pi (pj) ;
endtikzpicture
enddocument


enter image description here



Yet another possibility would be to employ Henri Menke's trick to remember node contents, I'd be happy to spell that out if you ask me to.







share|improve this answer














share|improve this answer



share|improve this answer








edited Aug 21 at 16:33

























answered Aug 21 at 15:57









marmot

55.4k460121




55.4k460121











  • Nifty! Thanks a lot, that does it!
    – Holger Karl
    Aug 21 at 16:01










  • marmot: Your edited answer is enlightening, thanks. I had seen @percusse comment in the other thread, but hadn't understood its relevance here. A bit counterintuitive to have to use noexpand to expand i, though :-). The approach via macro seems quite heavy-weight?
    – Holger Karl
    Aug 22 at 6:30










  • @HolgerKarl This expansion thingy is something that one has sometimes to do in foreach loops and more often in pgfplots. It ensures here that when pgfkeyssetvalue gets "executed" i and value are already expanded. Whether or not this is "heavy weight" is a matter of taste. If you look into the codes in packages, you will often see tons of expanafter and noexpand statements. But yes, it is "nicer" if one can do without those. ;-)
    – marmot
    Aug 22 at 10:11
















  • Nifty! Thanks a lot, that does it!
    – Holger Karl
    Aug 21 at 16:01










  • marmot: Your edited answer is enlightening, thanks. I had seen @percusse comment in the other thread, but hadn't understood its relevance here. A bit counterintuitive to have to use noexpand to expand i, though :-). The approach via macro seems quite heavy-weight?
    – Holger Karl
    Aug 22 at 6:30










  • @HolgerKarl This expansion thingy is something that one has sometimes to do in foreach loops and more often in pgfplots. It ensures here that when pgfkeyssetvalue gets "executed" i and value are already expanded. Whether or not this is "heavy weight" is a matter of taste. If you look into the codes in packages, you will often see tons of expanafter and noexpand statements. But yes, it is "nicer" if one can do without those. ;-)
    – marmot
    Aug 22 at 10:11















Nifty! Thanks a lot, that does it!
– Holger Karl
Aug 21 at 16:01




Nifty! Thanks a lot, that does it!
– Holger Karl
Aug 21 at 16:01












marmot: Your edited answer is enlightening, thanks. I had seen @percusse comment in the other thread, but hadn't understood its relevance here. A bit counterintuitive to have to use noexpand to expand i, though :-). The approach via macro seems quite heavy-weight?
– Holger Karl
Aug 22 at 6:30




marmot: Your edited answer is enlightening, thanks. I had seen @percusse comment in the other thread, but hadn't understood its relevance here. A bit counterintuitive to have to use noexpand to expand i, though :-). The approach via macro seems quite heavy-weight?
– Holger Karl
Aug 22 at 6:30












@HolgerKarl This expansion thingy is something that one has sometimes to do in foreach loops and more often in pgfplots. It ensures here that when pgfkeyssetvalue gets "executed" i and value are already expanded. Whether or not this is "heavy weight" is a matter of taste. If you look into the codes in packages, you will often see tons of expanafter and noexpand statements. But yes, it is "nicer" if one can do without those. ;-)
– marmot
Aug 22 at 10:11




@HolgerKarl This expansion thingy is something that one has sometimes to do in foreach loops and more often in pgfplots. It ensures here that when pgfkeyssetvalue gets "executed" i and value are already expanded. Whether or not this is "heavy weight" is a matter of taste. If you look into the codes in packages, you will often see tons of expanafter and noexpand statements. But yes, it is "nicer" if one can do without those. ;-)
– marmot
Aug 22 at 10:11










up vote
4
down vote













Just for fun, a single foreach that does what you want.



documentclass[tikz,margin=2mm]standalone

usepackagetikz

begindocument

begintikzpicture
draw [dotted] (0,0) circle (2cm);

foreach angle/value [count = i, count=j from 0, remember=value as oldvalue] in 0/17, 45/22, 80/5, 140/12
node [circle, draw, fill=white] (pi) at (angle:2cm) value;
ifnumj>0
draw[->] (pj) to [bend right=45] node[midway,auto,swap] oldvalue (pi);
fi
ifnumi=4
draw[->] (pi) to [bend right=45] node[midway,auto,swap] value (p1);
fi

endtikzpicture

enddocument


enter image description here






share|improve this answer
















  • 1




    Oops, I spent the evening looking to do like you and you were faster. I had not thought at all to use two different counts, one starting at 0, the other at 1, your solution is more beautiful than mine :)
    – AndréC
    Aug 21 at 21:16







  • 1




    @AndréC Thanks! I think your remember=i as lasti (initially 4) is also very clever, saves you to do the int(mod(...)) stuff. I will try to remember that :)
    – Max
    Aug 22 at 6:19






  • 1




    Unfortunately, a single loop does not work for me - I am drawing the base graph and then different annotations on top of it (not shown in my question). But yes, that is also nice with the lasti - didnt know about that either :-)
    – Holger Karl
    Aug 22 at 6:26














up vote
4
down vote













Just for fun, a single foreach that does what you want.



documentclass[tikz,margin=2mm]standalone

usepackagetikz

begindocument

begintikzpicture
draw [dotted] (0,0) circle (2cm);

foreach angle/value [count = i, count=j from 0, remember=value as oldvalue] in 0/17, 45/22, 80/5, 140/12
node [circle, draw, fill=white] (pi) at (angle:2cm) value;
ifnumj>0
draw[->] (pj) to [bend right=45] node[midway,auto,swap] oldvalue (pi);
fi
ifnumi=4
draw[->] (pi) to [bend right=45] node[midway,auto,swap] value (p1);
fi

endtikzpicture

enddocument


enter image description here






share|improve this answer
















  • 1




    Oops, I spent the evening looking to do like you and you were faster. I had not thought at all to use two different counts, one starting at 0, the other at 1, your solution is more beautiful than mine :)
    – AndréC
    Aug 21 at 21:16







  • 1




    @AndréC Thanks! I think your remember=i as lasti (initially 4) is also very clever, saves you to do the int(mod(...)) stuff. I will try to remember that :)
    – Max
    Aug 22 at 6:19






  • 1




    Unfortunately, a single loop does not work for me - I am drawing the base graph and then different annotations on top of it (not shown in my question). But yes, that is also nice with the lasti - didnt know about that either :-)
    – Holger Karl
    Aug 22 at 6:26












up vote
4
down vote










up vote
4
down vote









Just for fun, a single foreach that does what you want.



documentclass[tikz,margin=2mm]standalone

usepackagetikz

begindocument

begintikzpicture
draw [dotted] (0,0) circle (2cm);

foreach angle/value [count = i, count=j from 0, remember=value as oldvalue] in 0/17, 45/22, 80/5, 140/12
node [circle, draw, fill=white] (pi) at (angle:2cm) value;
ifnumj>0
draw[->] (pj) to [bend right=45] node[midway,auto,swap] oldvalue (pi);
fi
ifnumi=4
draw[->] (pi) to [bend right=45] node[midway,auto,swap] value (p1);
fi

endtikzpicture

enddocument


enter image description here






share|improve this answer












Just for fun, a single foreach that does what you want.



documentclass[tikz,margin=2mm]standalone

usepackagetikz

begindocument

begintikzpicture
draw [dotted] (0,0) circle (2cm);

foreach angle/value [count = i, count=j from 0, remember=value as oldvalue] in 0/17, 45/22, 80/5, 140/12
node [circle, draw, fill=white] (pi) at (angle:2cm) value;
ifnumj>0
draw[->] (pj) to [bend right=45] node[midway,auto,swap] oldvalue (pi);
fi
ifnumi=4
draw[->] (pi) to [bend right=45] node[midway,auto,swap] value (p1);
fi

endtikzpicture

enddocument


enter image description here







share|improve this answer












share|improve this answer



share|improve this answer










answered Aug 21 at 16:46









Max

5,89811727




5,89811727







  • 1




    Oops, I spent the evening looking to do like you and you were faster. I had not thought at all to use two different counts, one starting at 0, the other at 1, your solution is more beautiful than mine :)
    – AndréC
    Aug 21 at 21:16







  • 1




    @AndréC Thanks! I think your remember=i as lasti (initially 4) is also very clever, saves you to do the int(mod(...)) stuff. I will try to remember that :)
    – Max
    Aug 22 at 6:19






  • 1




    Unfortunately, a single loop does not work for me - I am drawing the base graph and then different annotations on top of it (not shown in my question). But yes, that is also nice with the lasti - didnt know about that either :-)
    – Holger Karl
    Aug 22 at 6:26












  • 1




    Oops, I spent the evening looking to do like you and you were faster. I had not thought at all to use two different counts, one starting at 0, the other at 1, your solution is more beautiful than mine :)
    – AndréC
    Aug 21 at 21:16







  • 1




    @AndréC Thanks! I think your remember=i as lasti (initially 4) is also very clever, saves you to do the int(mod(...)) stuff. I will try to remember that :)
    – Max
    Aug 22 at 6:19






  • 1




    Unfortunately, a single loop does not work for me - I am drawing the base graph and then different annotations on top of it (not shown in my question). But yes, that is also nice with the lasti - didnt know about that either :-)
    – Holger Karl
    Aug 22 at 6:26







1




1




Oops, I spent the evening looking to do like you and you were faster. I had not thought at all to use two different counts, one starting at 0, the other at 1, your solution is more beautiful than mine :)
– AndréC
Aug 21 at 21:16





Oops, I spent the evening looking to do like you and you were faster. I had not thought at all to use two different counts, one starting at 0, the other at 1, your solution is more beautiful than mine :)
– AndréC
Aug 21 at 21:16





1




1




@AndréC Thanks! I think your remember=i as lasti (initially 4) is also very clever, saves you to do the int(mod(...)) stuff. I will try to remember that :)
– Max
Aug 22 at 6:19




@AndréC Thanks! I think your remember=i as lasti (initially 4) is also very clever, saves you to do the int(mod(...)) stuff. I will try to remember that :)
– Max
Aug 22 at 6:19




1




1




Unfortunately, a single loop does not work for me - I am drawing the base graph and then different annotations on top of it (not shown in my question). But yes, that is also nice with the lasti - didnt know about that either :-)
– Holger Karl
Aug 22 at 6:26




Unfortunately, a single loop does not work for me - I am drawing the base graph and then different annotations on top of it (not shown in my question). But yes, that is also nice with the lasti - didnt know about that either :-)
– Holger Karl
Aug 22 at 6:26










up vote
1
down vote













It is possible to solve your problem without using pgf keys but only using the native capabilities of foreach operation.



Here, I used a first loop to draw the nodes and a second to create the arrows between the nodes with the edge operation



documentclass[tikz]standalone

begindocument
begintikzpicture
draw [dotted] (0,0) circle (2cm);

% create the node
foreach angle/value [count=i,remember=angle as lastangle (initially 140),remember=i as lasti (initially 4)] in 0/17, 45/22, 80/5, 140/12
node (i) at (angle:2cm) value;

% draw arrow with edge operation
foreach value [count=i,remember =i as lasti (initially 4),remember=value as lvalue (initially 12)] in 17,22,5,12
path[->](lasti) edge[bend right=45] node[midway,auto,swap]lvalue(i);

endtikzpicture

enddocument


noeuds






share|improve this answer


















  • 1




    See above; answer to @Max
    – Holger Karl
    Aug 22 at 6:26














up vote
1
down vote













It is possible to solve your problem without using pgf keys but only using the native capabilities of foreach operation.



Here, I used a first loop to draw the nodes and a second to create the arrows between the nodes with the edge operation



documentclass[tikz]standalone

begindocument
begintikzpicture
draw [dotted] (0,0) circle (2cm);

% create the node
foreach angle/value [count=i,remember=angle as lastangle (initially 140),remember=i as lasti (initially 4)] in 0/17, 45/22, 80/5, 140/12
node (i) at (angle:2cm) value;

% draw arrow with edge operation
foreach value [count=i,remember =i as lasti (initially 4),remember=value as lvalue (initially 12)] in 17,22,5,12
path[->](lasti) edge[bend right=45] node[midway,auto,swap]lvalue(i);

endtikzpicture

enddocument


noeuds






share|improve this answer


















  • 1




    See above; answer to @Max
    – Holger Karl
    Aug 22 at 6:26












up vote
1
down vote










up vote
1
down vote









It is possible to solve your problem without using pgf keys but only using the native capabilities of foreach operation.



Here, I used a first loop to draw the nodes and a second to create the arrows between the nodes with the edge operation



documentclass[tikz]standalone

begindocument
begintikzpicture
draw [dotted] (0,0) circle (2cm);

% create the node
foreach angle/value [count=i,remember=angle as lastangle (initially 140),remember=i as lasti (initially 4)] in 0/17, 45/22, 80/5, 140/12
node (i) at (angle:2cm) value;

% draw arrow with edge operation
foreach value [count=i,remember =i as lasti (initially 4),remember=value as lvalue (initially 12)] in 17,22,5,12
path[->](lasti) edge[bend right=45] node[midway,auto,swap]lvalue(i);

endtikzpicture

enddocument


noeuds






share|improve this answer














It is possible to solve your problem without using pgf keys but only using the native capabilities of foreach operation.



Here, I used a first loop to draw the nodes and a second to create the arrows between the nodes with the edge operation



documentclass[tikz]standalone

begindocument
begintikzpicture
draw [dotted] (0,0) circle (2cm);

% create the node
foreach angle/value [count=i,remember=angle as lastangle (initially 140),remember=i as lasti (initially 4)] in 0/17, 45/22, 80/5, 140/12
node (i) at (angle:2cm) value;

% draw arrow with edge operation
foreach value [count=i,remember =i as lasti (initially 4),remember=value as lvalue (initially 12)] in 17,22,5,12
path[->](lasti) edge[bend right=45] node[midway,auto,swap]lvalue(i);

endtikzpicture

enddocument


noeuds







share|improve this answer














share|improve this answer



share|improve this answer








edited Aug 22 at 8:57

























answered Aug 21 at 21:14









AndréC

2,872728




2,872728







  • 1




    See above; answer to @Max
    – Holger Karl
    Aug 22 at 6:26












  • 1




    See above; answer to @Max
    – Holger Karl
    Aug 22 at 6:26







1




1




See above; answer to @Max
– Holger Karl
Aug 22 at 6:26




See above; answer to @Max
– Holger Karl
Aug 22 at 6:26

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f447009%2fhow-to-compute-the-key-of-a-pgfkeyssetvalue-command%23new-answer', 'question_page');

);

Post as a guest













































































Comments

Popular posts from this blog

What does second last employer means? [closed]

List of Gilmore Girls characters

One-line joke