Arithmetic inside tikz
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I'm having difficulty performing arithmetic inside tikz
.
I've written:
foreach s in 6,...,8
node[draw,red,circle] at (0:(s-2)cm) $s$;
Somehow the arithmetic (s-2)
is not working, I think its the cm
that's causing the issue but I need the measurement in cm
.
Also if I write:
node[draw,red,circle] at (0:s cm) $(s-2)$;
the arithmetic does not work and LaTeX just merrily shows (6-2) (7-2)
etc...
tikz-pgf foreach
New contributor
user50123 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
2
down vote
favorite
I'm having difficulty performing arithmetic inside tikz
.
I've written:
foreach s in 6,...,8
node[draw,red,circle] at (0:(s-2)cm) $s$;
Somehow the arithmetic (s-2)
is not working, I think its the cm
that's causing the issue but I need the measurement in cm
.
Also if I write:
node[draw,red,circle] at (0:s cm) $(s-2)$;
the arithmetic does not work and LaTeX just merrily shows (6-2) (7-2)
etc...
tikz-pgf foreach
New contributor
user50123 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
Welcome to TeX.SE! Please make your code snippet compilable ...
– Kurt
3 hours ago
2
Here, you must use braces around your formula (tex.stackexchange.com/a/218542/14500) and multiply by1cm
:(0:(s-2)*1cm)
.
– Paul Gaborit
3 hours ago
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I'm having difficulty performing arithmetic inside tikz
.
I've written:
foreach s in 6,...,8
node[draw,red,circle] at (0:(s-2)cm) $s$;
Somehow the arithmetic (s-2)
is not working, I think its the cm
that's causing the issue but I need the measurement in cm
.
Also if I write:
node[draw,red,circle] at (0:s cm) $(s-2)$;
the arithmetic does not work and LaTeX just merrily shows (6-2) (7-2)
etc...
tikz-pgf foreach
New contributor
user50123 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I'm having difficulty performing arithmetic inside tikz
.
I've written:
foreach s in 6,...,8
node[draw,red,circle] at (0:(s-2)cm) $s$;
Somehow the arithmetic (s-2)
is not working, I think its the cm
that's causing the issue but I need the measurement in cm
.
Also if I write:
node[draw,red,circle] at (0:s cm) $(s-2)$;
the arithmetic does not work and LaTeX just merrily shows (6-2) (7-2)
etc...
tikz-pgf foreach
tikz-pgf foreach
New contributor
user50123 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
user50123 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 3 hours ago


CarLaTeX
26.2k444116
26.2k444116
New contributor
user50123 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 3 hours ago
user50123
111
111
New contributor
user50123 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
user50123 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
user50123 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
Welcome to TeX.SE! Please make your code snippet compilable ...
– Kurt
3 hours ago
2
Here, you must use braces around your formula (tex.stackexchange.com/a/218542/14500) and multiply by1cm
:(0:(s-2)*1cm)
.
– Paul Gaborit
3 hours ago
add a comment |Â
1
Welcome to TeX.SE! Please make your code snippet compilable ...
– Kurt
3 hours ago
2
Here, you must use braces around your formula (tex.stackexchange.com/a/218542/14500) and multiply by1cm
:(0:(s-2)*1cm)
.
– Paul Gaborit
3 hours ago
1
1
Welcome to TeX.SE! Please make your code snippet compilable ...
– Kurt
3 hours ago
Welcome to TeX.SE! Please make your code snippet compilable ...
– Kurt
3 hours ago
2
2
Here, you must use braces around your formula (tex.stackexchange.com/a/218542/14500) and multiply by
1cm
: (0:(s-2)*1cm)
.– Paul Gaborit
3 hours ago
Here, you must use braces around your formula (tex.stackexchange.com/a/218542/14500) and multiply by
1cm
: (0:(s-2)*1cm)
.– Paul Gaborit
3 hours ago
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
2
down vote
You can't use arithmetic as you shown directly (in the description of a node or if you explicitly put a unit of measure after it).
Just use evaluate
option of the foreach
macro.
Here I create a new variable mys
which assumes the value s-2
.
In my first tikzpicture
, mys
is used for positioning; in the second, for description:
documentclassarticle
usepackagetikz
begindocument
begintikzpicture
foreach[evaluate=s as mys using int(s-2)] s in 6,...,8
node[draw,red,circle] at (0:mys cm) $s$;
endtikzpicture
begintikzpicture
foreach[evaluate=s as mys using int(s-2)] s in 6,...,8
node[draw,red,circle] at (0:s cm) $mys$;
endtikzpicture
enddocument
add a comment |Â
up vote
1
down vote
The unit of tikz is the cm
, so it is useless to specify it. As for the calculations, they are done here without the need for brackets.
documentclass[tikz,border=5mm]standalone
usetikzlibraryshadows,fadings
usetikzlibrarycalc
usetikzlibrarypositioning
begindocument
begintikzpicture
node[draw,blue,circle] at(0:2cm)4;
node[draw,blue,circle] at(0:3)5;
node[draw,blue,circle] at(0:4cm)6;
foreach s in 6,...,8
node[fill=red,circle,opacity=.5] at (0:s-2) $s$;
endtikzpicture
enddocument
If you still want to specify the unit, it is necessary to do it after each of the Numbers: (0:s cm-2cm) $s$;
Or to do as indicated by @PaulGaborit by factoring the unit: (0:(s-2)*1cm)
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
You can't use arithmetic as you shown directly (in the description of a node or if you explicitly put a unit of measure after it).
Just use evaluate
option of the foreach
macro.
Here I create a new variable mys
which assumes the value s-2
.
In my first tikzpicture
, mys
is used for positioning; in the second, for description:
documentclassarticle
usepackagetikz
begindocument
begintikzpicture
foreach[evaluate=s as mys using int(s-2)] s in 6,...,8
node[draw,red,circle] at (0:mys cm) $s$;
endtikzpicture
begintikzpicture
foreach[evaluate=s as mys using int(s-2)] s in 6,...,8
node[draw,red,circle] at (0:s cm) $mys$;
endtikzpicture
enddocument
add a comment |Â
up vote
2
down vote
You can't use arithmetic as you shown directly (in the description of a node or if you explicitly put a unit of measure after it).
Just use evaluate
option of the foreach
macro.
Here I create a new variable mys
which assumes the value s-2
.
In my first tikzpicture
, mys
is used for positioning; in the second, for description:
documentclassarticle
usepackagetikz
begindocument
begintikzpicture
foreach[evaluate=s as mys using int(s-2)] s in 6,...,8
node[draw,red,circle] at (0:mys cm) $s$;
endtikzpicture
begintikzpicture
foreach[evaluate=s as mys using int(s-2)] s in 6,...,8
node[draw,red,circle] at (0:s cm) $mys$;
endtikzpicture
enddocument
add a comment |Â
up vote
2
down vote
up vote
2
down vote
You can't use arithmetic as you shown directly (in the description of a node or if you explicitly put a unit of measure after it).
Just use evaluate
option of the foreach
macro.
Here I create a new variable mys
which assumes the value s-2
.
In my first tikzpicture
, mys
is used for positioning; in the second, for description:
documentclassarticle
usepackagetikz
begindocument
begintikzpicture
foreach[evaluate=s as mys using int(s-2)] s in 6,...,8
node[draw,red,circle] at (0:mys cm) $s$;
endtikzpicture
begintikzpicture
foreach[evaluate=s as mys using int(s-2)] s in 6,...,8
node[draw,red,circle] at (0:s cm) $mys$;
endtikzpicture
enddocument
You can't use arithmetic as you shown directly (in the description of a node or if you explicitly put a unit of measure after it).
Just use evaluate
option of the foreach
macro.
Here I create a new variable mys
which assumes the value s-2
.
In my first tikzpicture
, mys
is used for positioning; in the second, for description:
documentclassarticle
usepackagetikz
begindocument
begintikzpicture
foreach[evaluate=s as mys using int(s-2)] s in 6,...,8
node[draw,red,circle] at (0:mys cm) $s$;
endtikzpicture
begintikzpicture
foreach[evaluate=s as mys using int(s-2)] s in 6,...,8
node[draw,red,circle] at (0:s cm) $mys$;
endtikzpicture
enddocument
edited 3 hours ago
answered 3 hours ago


CarLaTeX
26.2k444116
26.2k444116
add a comment |Â
add a comment |Â
up vote
1
down vote
The unit of tikz is the cm
, so it is useless to specify it. As for the calculations, they are done here without the need for brackets.
documentclass[tikz,border=5mm]standalone
usetikzlibraryshadows,fadings
usetikzlibrarycalc
usetikzlibrarypositioning
begindocument
begintikzpicture
node[draw,blue,circle] at(0:2cm)4;
node[draw,blue,circle] at(0:3)5;
node[draw,blue,circle] at(0:4cm)6;
foreach s in 6,...,8
node[fill=red,circle,opacity=.5] at (0:s-2) $s$;
endtikzpicture
enddocument
If you still want to specify the unit, it is necessary to do it after each of the Numbers: (0:s cm-2cm) $s$;
Or to do as indicated by @PaulGaborit by factoring the unit: (0:(s-2)*1cm)
add a comment |Â
up vote
1
down vote
The unit of tikz is the cm
, so it is useless to specify it. As for the calculations, they are done here without the need for brackets.
documentclass[tikz,border=5mm]standalone
usetikzlibraryshadows,fadings
usetikzlibrarycalc
usetikzlibrarypositioning
begindocument
begintikzpicture
node[draw,blue,circle] at(0:2cm)4;
node[draw,blue,circle] at(0:3)5;
node[draw,blue,circle] at(0:4cm)6;
foreach s in 6,...,8
node[fill=red,circle,opacity=.5] at (0:s-2) $s$;
endtikzpicture
enddocument
If you still want to specify the unit, it is necessary to do it after each of the Numbers: (0:s cm-2cm) $s$;
Or to do as indicated by @PaulGaborit by factoring the unit: (0:(s-2)*1cm)
add a comment |Â
up vote
1
down vote
up vote
1
down vote
The unit of tikz is the cm
, so it is useless to specify it. As for the calculations, they are done here without the need for brackets.
documentclass[tikz,border=5mm]standalone
usetikzlibraryshadows,fadings
usetikzlibrarycalc
usetikzlibrarypositioning
begindocument
begintikzpicture
node[draw,blue,circle] at(0:2cm)4;
node[draw,blue,circle] at(0:3)5;
node[draw,blue,circle] at(0:4cm)6;
foreach s in 6,...,8
node[fill=red,circle,opacity=.5] at (0:s-2) $s$;
endtikzpicture
enddocument
If you still want to specify the unit, it is necessary to do it after each of the Numbers: (0:s cm-2cm) $s$;
Or to do as indicated by @PaulGaborit by factoring the unit: (0:(s-2)*1cm)
The unit of tikz is the cm
, so it is useless to specify it. As for the calculations, they are done here without the need for brackets.
documentclass[tikz,border=5mm]standalone
usetikzlibraryshadows,fadings
usetikzlibrarycalc
usetikzlibrarypositioning
begindocument
begintikzpicture
node[draw,blue,circle] at(0:2cm)4;
node[draw,blue,circle] at(0:3)5;
node[draw,blue,circle] at(0:4cm)6;
foreach s in 6,...,8
node[fill=red,circle,opacity=.5] at (0:s-2) $s$;
endtikzpicture
enddocument
If you still want to specify the unit, it is necessary to do it after each of the Numbers: (0:s cm-2cm) $s$;
Or to do as indicated by @PaulGaborit by factoring the unit: (0:(s-2)*1cm)
edited 1 hour ago
answered 3 hours ago
AndréC
4,3021833
4,3021833
add a comment |Â
add a comment |Â
user50123 is a new contributor. Be nice, and check out our Code of Conduct.
user50123 is a new contributor. Be nice, and check out our Code of Conduct.
user50123 is a new contributor. Be nice, and check out our Code of Conduct.
user50123 is a new contributor. Be nice, and check out our Code of Conduct.
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%2f457021%2farithmetic-inside-tikz%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
1
Welcome to TeX.SE! Please make your code snippet compilable ...
– Kurt
3 hours ago
2
Here, you must use braces around your formula (tex.stackexchange.com/a/218542/14500) and multiply by
1cm
:(0:(s-2)*1cm)
.– Paul Gaborit
3 hours ago