Optional args for TikZ style
Clash 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.
tikz-pgf tikz-styles arguments
add a comment |Â
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.
tikz-pgf tikz-styles arguments
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 thepos=0.7
still works, because it is a/tikz
key and not a/pgf/decoration
key. Otherwise you could usetikzsetmidcirclepos/.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
add a comment |Â
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.
tikz-pgf tikz-styles arguments
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
tikz-pgf tikz-styles arguments
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 thepos=0.7
still works, because it is a/tikz
key and not a/pgf/decoration
key. Otherwise you could usetikzsetmidcirclepos/.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
add a comment |Â
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 thepos=0.7
still works, because it is a/tikz
key and not a/pgf/decoration
key. Otherwise you could usetikzsetmidcirclepos/.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
add a comment |Â
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
1
@marmot What's wrong with macros in the context of a macro machine like TeX? Accessing a macro seems to be lightweight compared topgfkeysvalueof
.
â gernot
Sep 5 at 14:55
add a comment |Â
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
1
@marmot What's wrong with macros in the context of a macro machine like TeX? Accessing a macro seems to be lightweight compared topgfkeysvalueof
.
â gernot
Sep 5 at 14:55
add a comment |Â
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
1
@marmot What's wrong with macros in the context of a macro machine like TeX? Accessing a macro seems to be lightweight compared topgfkeysvalueof
.
â gernot
Sep 5 at 14:55
add a comment |Â
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
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
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 topgfkeysvalueof
.
â gernot
Sep 5 at 14:55
add a comment |Â
1
@marmot What's wrong with macros in the context of a macro machine like TeX? Accessing a macro seems to be lightweight compared topgfkeysvalueof
.
â 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
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%2f449450%2foptional-args-for-tikz-style%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
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 usetikzsetmidcirclepos/.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