Optional args for TikZ style

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











up vote
6
down vote

favorite












I have a defined a TikZ style "midcircle" that decorates a path with, say, a small circle in the middle (with the decorations.markings library, setting "pos=0.5"). E.g.



draw (0,0)edge[midcircle](1,0);


would draw a straight line with a circle in the middle. Now I would like to be able to change the position of the circle by defining another style, say "midcirclepos", such that e.g.



draw (0,0)edge[midcircle,midcirclepos=0.7](1,0);


would draw the circle at "pos=0.7" instead "pos=0.5". I think I've seen such constructions, but I can't find any more how to implement it.



By the way, I can't use the usual default arguments for TikZ styles, because my "midcircle" already takes other arguments that also have defaults.










share|improve this question





















  • just put a variable in the value that you want to change like pos=#1 in your tikz style definition, then put the value midcircle=0.5, or another value like in this example see how it is defined InLineArrow style,
    – J Leon V.
    Sep 5 at 14:15











  • @JLeonV.: This doesn't work for me: The thing is that I want to have pos=0.5 as the default value, but I also have 2 other arguments passed to "midcircle" one of which also has a default value. However TikZ cannot handle more than one default value. (See last sentence)
    – Andi Bauer
    Sep 5 at 14:20










  • My first guess would be that the pos=0.7 still works, because it is a /tikz key and not a /pgf/decoration key. Otherwise you could use tikzsetmidcirclepos/.forward to=/tikz/pos, but without an MWE who knows for certain.
    – Max
    Sep 5 at 14:20










  • @AndiBauer, there is a good answer from gernot , and some that I learn too +1
    – J Leon V.
    Sep 5 at 14:23














up vote
6
down vote

favorite












I have a defined a TikZ style "midcircle" that decorates a path with, say, a small circle in the middle (with the decorations.markings library, setting "pos=0.5"). E.g.



draw (0,0)edge[midcircle](1,0);


would draw a straight line with a circle in the middle. Now I would like to be able to change the position of the circle by defining another style, say "midcirclepos", such that e.g.



draw (0,0)edge[midcircle,midcirclepos=0.7](1,0);


would draw the circle at "pos=0.7" instead "pos=0.5". I think I've seen such constructions, but I can't find any more how to implement it.



By the way, I can't use the usual default arguments for TikZ styles, because my "midcircle" already takes other arguments that also have defaults.










share|improve this question





















  • just put a variable in the value that you want to change like pos=#1 in your tikz style definition, then put the value midcircle=0.5, or another value like in this example see how it is defined InLineArrow style,
    – J Leon V.
    Sep 5 at 14:15











  • @JLeonV.: This doesn't work for me: The thing is that I want to have pos=0.5 as the default value, but I also have 2 other arguments passed to "midcircle" one of which also has a default value. However TikZ cannot handle more than one default value. (See last sentence)
    – Andi Bauer
    Sep 5 at 14:20










  • My first guess would be that the pos=0.7 still works, because it is a /tikz key and not a /pgf/decoration key. Otherwise you could use tikzsetmidcirclepos/.forward to=/tikz/pos, but without an MWE who knows for certain.
    – Max
    Sep 5 at 14:20










  • @AndiBauer, there is a good answer from gernot , and some that I learn too +1
    – J Leon V.
    Sep 5 at 14:23












up vote
6
down vote

favorite









up vote
6
down vote

favorite











I have a defined a TikZ style "midcircle" that decorates a path with, say, a small circle in the middle (with the decorations.markings library, setting "pos=0.5"). E.g.



draw (0,0)edge[midcircle](1,0);


would draw a straight line with a circle in the middle. Now I would like to be able to change the position of the circle by defining another style, say "midcirclepos", such that e.g.



draw (0,0)edge[midcircle,midcirclepos=0.7](1,0);


would draw the circle at "pos=0.7" instead "pos=0.5". I think I've seen such constructions, but I can't find any more how to implement it.



By the way, I can't use the usual default arguments for TikZ styles, because my "midcircle" already takes other arguments that also have defaults.










share|improve this question













I have a defined a TikZ style "midcircle" that decorates a path with, say, a small circle in the middle (with the decorations.markings library, setting "pos=0.5"). E.g.



draw (0,0)edge[midcircle](1,0);


would draw a straight line with a circle in the middle. Now I would like to be able to change the position of the circle by defining another style, say "midcirclepos", such that e.g.



draw (0,0)edge[midcircle,midcirclepos=0.7](1,0);


would draw the circle at "pos=0.7" instead "pos=0.5". I think I've seen such constructions, but I can't find any more how to implement it.



By the way, I can't use the usual default arguments for TikZ styles, because my "midcircle" already takes other arguments that also have defaults.







tikz-pgf tikz-styles arguments






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Sep 5 at 13:19









Andi Bauer

3178




3178











  • just put a variable in the value that you want to change like pos=#1 in your tikz style definition, then put the value midcircle=0.5, or another value like in this example see how it is defined InLineArrow style,
    – J Leon V.
    Sep 5 at 14:15











  • @JLeonV.: This doesn't work for me: The thing is that I want to have pos=0.5 as the default value, but I also have 2 other arguments passed to "midcircle" one of which also has a default value. However TikZ cannot handle more than one default value. (See last sentence)
    – Andi Bauer
    Sep 5 at 14:20










  • My first guess would be that the pos=0.7 still works, because it is a /tikz key and not a /pgf/decoration key. Otherwise you could use tikzsetmidcirclepos/.forward to=/tikz/pos, but without an MWE who knows for certain.
    – Max
    Sep 5 at 14:20










  • @AndiBauer, there is a good answer from gernot , and some that I learn too +1
    – J Leon V.
    Sep 5 at 14:23
















  • just put a variable in the value that you want to change like pos=#1 in your tikz style definition, then put the value midcircle=0.5, or another value like in this example see how it is defined InLineArrow style,
    – J Leon V.
    Sep 5 at 14:15











  • @JLeonV.: This doesn't work for me: The thing is that I want to have pos=0.5 as the default value, but I also have 2 other arguments passed to "midcircle" one of which also has a default value. However TikZ cannot handle more than one default value. (See last sentence)
    – Andi Bauer
    Sep 5 at 14:20










  • My first guess would be that the pos=0.7 still works, because it is a /tikz key and not a /pgf/decoration key. Otherwise you could use tikzsetmidcirclepos/.forward to=/tikz/pos, but without an MWE who knows for certain.
    – Max
    Sep 5 at 14:20










  • @AndiBauer, there is a good answer from gernot , and some that I learn too +1
    – J Leon V.
    Sep 5 at 14:23















just put a variable in the value that you want to change like pos=#1 in your tikz style definition, then put the value midcircle=0.5, or another value like in this example see how it is defined InLineArrow style,
– J Leon V.
Sep 5 at 14:15





just put a variable in the value that you want to change like pos=#1 in your tikz style definition, then put the value midcircle=0.5, or another value like in this example see how it is defined InLineArrow style,
– J Leon V.
Sep 5 at 14:15













@JLeonV.: This doesn't work for me: The thing is that I want to have pos=0.5 as the default value, but I also have 2 other arguments passed to "midcircle" one of which also has a default value. However TikZ cannot handle more than one default value. (See last sentence)
– Andi Bauer
Sep 5 at 14:20




@JLeonV.: This doesn't work for me: The thing is that I want to have pos=0.5 as the default value, but I also have 2 other arguments passed to "midcircle" one of which also has a default value. However TikZ cannot handle more than one default value. (See last sentence)
– Andi Bauer
Sep 5 at 14:20












My first guess would be that the pos=0.7 still works, because it is a /tikz key and not a /pgf/decoration key. Otherwise you could use tikzsetmidcirclepos/.forward to=/tikz/pos, but without an MWE who knows for certain.
– Max
Sep 5 at 14:20




My first guess would be that the pos=0.7 still works, because it is a /tikz key and not a /pgf/decoration key. Otherwise you could use tikzsetmidcirclepos/.forward to=/tikz/pos, but without an MWE who knows for certain.
– Max
Sep 5 at 14:20












@AndiBauer, there is a good answer from gernot , and some that I learn too +1
– J Leon V.
Sep 5 at 14:23




@AndiBauer, there is a good answer from gernot , and some that I learn too +1
– J Leon V.
Sep 5 at 14:23










1 Answer
1






active

oldest

votes

















up vote
7
down vote



accepted










Define a key midcirclepos that takes as argument a value and stores it in the macro midcirclepos. Initialize it with 0.5 and use midcirclepos to access the value.



tikzsetmidcirclepos/.store in=midcirclepos,midcirclepos=0.5


Here is an example that also shows that the change to midcirclepos is temporary.



documentclassarticle 
usepackagetikz
usetikzlibrarydecorations.markings
tikzsetmidcirclepos/.store in=midcirclepos,midcirclepos=0.5
begindocument
begintikzpicture[
midcircle/.style =
postaction=decorate,
decoration =
markings,
mark = at position midcirclepos
with draw (0,0) circle (0.1);
,

]
draw (0,0) edge [midcircle] (1,0);
draw (0,-1) edge [midcircle,midcirclepos=0.7] (1,-1);
draw (0,-2) edge [midcircle] (1,-2);
endtikzpicture
enddocument


enter image description here






share|improve this answer
















  • 1




    @marmot What's wrong with macros in the context of a macro machine like TeX? Accessing a macro seems to be lightweight compared to pgfkeysvalueof.
    – gernot
    Sep 5 at 14:55










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%2f449450%2foptional-args-for-tikz-style%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
7
down vote



accepted










Define a key midcirclepos that takes as argument a value and stores it in the macro midcirclepos. Initialize it with 0.5 and use midcirclepos to access the value.



tikzsetmidcirclepos/.store in=midcirclepos,midcirclepos=0.5


Here is an example that also shows that the change to midcirclepos is temporary.



documentclassarticle 
usepackagetikz
usetikzlibrarydecorations.markings
tikzsetmidcirclepos/.store in=midcirclepos,midcirclepos=0.5
begindocument
begintikzpicture[
midcircle/.style =
postaction=decorate,
decoration =
markings,
mark = at position midcirclepos
with draw (0,0) circle (0.1);
,

]
draw (0,0) edge [midcircle] (1,0);
draw (0,-1) edge [midcircle,midcirclepos=0.7] (1,-1);
draw (0,-2) edge [midcircle] (1,-2);
endtikzpicture
enddocument


enter image description here






share|improve this answer
















  • 1




    @marmot What's wrong with macros in the context of a macro machine like TeX? Accessing a macro seems to be lightweight compared to pgfkeysvalueof.
    – gernot
    Sep 5 at 14:55














up vote
7
down vote



accepted










Define a key midcirclepos that takes as argument a value and stores it in the macro midcirclepos. Initialize it with 0.5 and use midcirclepos to access the value.



tikzsetmidcirclepos/.store in=midcirclepos,midcirclepos=0.5


Here is an example that also shows that the change to midcirclepos is temporary.



documentclassarticle 
usepackagetikz
usetikzlibrarydecorations.markings
tikzsetmidcirclepos/.store in=midcirclepos,midcirclepos=0.5
begindocument
begintikzpicture[
midcircle/.style =
postaction=decorate,
decoration =
markings,
mark = at position midcirclepos
with draw (0,0) circle (0.1);
,

]
draw (0,0) edge [midcircle] (1,0);
draw (0,-1) edge [midcircle,midcirclepos=0.7] (1,-1);
draw (0,-2) edge [midcircle] (1,-2);
endtikzpicture
enddocument


enter image description here






share|improve this answer
















  • 1




    @marmot What's wrong with macros in the context of a macro machine like TeX? Accessing a macro seems to be lightweight compared to pgfkeysvalueof.
    – gernot
    Sep 5 at 14:55












up vote
7
down vote



accepted







up vote
7
down vote



accepted






Define a key midcirclepos that takes as argument a value and stores it in the macro midcirclepos. Initialize it with 0.5 and use midcirclepos to access the value.



tikzsetmidcirclepos/.store in=midcirclepos,midcirclepos=0.5


Here is an example that also shows that the change to midcirclepos is temporary.



documentclassarticle 
usepackagetikz
usetikzlibrarydecorations.markings
tikzsetmidcirclepos/.store in=midcirclepos,midcirclepos=0.5
begindocument
begintikzpicture[
midcircle/.style =
postaction=decorate,
decoration =
markings,
mark = at position midcirclepos
with draw (0,0) circle (0.1);
,

]
draw (0,0) edge [midcircle] (1,0);
draw (0,-1) edge [midcircle,midcirclepos=0.7] (1,-1);
draw (0,-2) edge [midcircle] (1,-2);
endtikzpicture
enddocument


enter image description here






share|improve this answer












Define a key midcirclepos that takes as argument a value and stores it in the macro midcirclepos. Initialize it with 0.5 and use midcirclepos to access the value.



tikzsetmidcirclepos/.store in=midcirclepos,midcirclepos=0.5


Here is an example that also shows that the change to midcirclepos is temporary.



documentclassarticle 
usepackagetikz
usetikzlibrarydecorations.markings
tikzsetmidcirclepos/.store in=midcirclepos,midcirclepos=0.5
begindocument
begintikzpicture[
midcircle/.style =
postaction=decorate,
decoration =
markings,
mark = at position midcirclepos
with draw (0,0) circle (0.1);
,

]
draw (0,0) edge [midcircle] (1,0);
draw (0,-1) edge [midcircle,midcirclepos=0.7] (1,-1);
draw (0,-2) edge [midcircle] (1,-2);
endtikzpicture
enddocument


enter image description here







share|improve this answer












share|improve this answer



share|improve this answer










answered Sep 5 at 14:20









gernot

26.2k22858




26.2k22858







  • 1




    @marmot What's wrong with macros in the context of a macro machine like TeX? Accessing a macro seems to be lightweight compared to pgfkeysvalueof.
    – gernot
    Sep 5 at 14:55












  • 1




    @marmot What's wrong with macros in the context of a macro machine like TeX? Accessing a macro seems to be lightweight compared to pgfkeysvalueof.
    – gernot
    Sep 5 at 14:55







1




1




@marmot What's wrong with macros in the context of a macro machine like TeX? Accessing a macro seems to be lightweight compared to pgfkeysvalueof.
– gernot
Sep 5 at 14:55




@marmot What's wrong with macros in the context of a macro machine like TeX? Accessing a macro seems to be lightweight compared to pgfkeysvalueof.
– gernot
Sep 5 at 14:55

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f449450%2foptional-args-for-tikz-style%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?