How to “add” units to results of pgfmathsetmacro?How can I produce a 'ring (or wheel) chart' like that on...
Why did IBM make the PC BIOS source code public?
How far did Gandalf and the Balrog drop from the bridge in Moria?
Creating some gif with tikz: Any idea to get better result?
How do some PhD students get 10+ papers? Is that what I need for landing good faculty position?
Scam? Phone call from "Department of Social Security" asking me to call back
Why won't the Republicans use a superdelegate system like the DNC in their nomination process?
Would the USA be eligible to join the European Union?
Telephone number in spoken words
Are employers legally allowed to pay employees in goods and services equal to or greater than the minimum wage?
How does the Athlete Feat affect the Ravnica Centaur playable race?
How was the murder committed?
Are there any cons in using rounded corners for bar graphs?
Shifting tenses in the middle of narration
When did Bilbo and Frodo learn that Gandalf was a Maia?
How much can I judge a company based on a phone screening?
Human with super efficient metabolism
Is it possible to arrive in the US without a C-1 visa for a transit flight
Lípínguapua dopo Pêpê
Pokemon Go: Gym Badge Over-completed?
Letting unbanned users comment
Why is there a large performance impact when looping over an array over 240 elements?
Is there a way to proportionalize fixed costs in a MILP?
What is the farthest a camera can see?
Is this n-speak?
How to “add” units to results of pgfmathsetmacro?
How can I produce a 'ring (or wheel) chart' like that on page 88 of the PGF manual?How to draw arcs linking two points in TikZ?Numerical conditional within tikz keys?circle vs arch with shorten — normal or bug?TikZ: Drawing an arc from an intersection to an intersectionDrawing rectilinear curves in Tikz, aka an Etch-a-Sketch drawingNode anchor centre of lineTikZ: create break in arc behind diameter?Drawing an arc between 2 nodes with a specific radiusHow to incorporate pgf macro into tikz path commandDrawing a curve (not necessarily an arc) in tikz-3dplot
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
This question is inspired by Jake's answer to this question. The problem is illustrated by this MWE:
documentclass{standalone}
usepackage{tikz}
begin{document}
defri{1.0cm} % define inner diameter
defro{2.0cm} % define outer diameter
begin{tikzpicture}
pgfmathsetmacro{dr}{ro-ri} % compute width
pgfmathsetmacro{rm}{(ri+ro)/2} % compute mean diameter
draw[red,line width=dr] (0:ro) arc (0:360:ro);
draw[black] (0,0) circle (ro) circle (ri);
end{tikzpicture}
end{document}
This produces the following output:
But this is not what I want, which is that the red strip should be between the two black circles. I expected that I could achieve this by replacing the first draw
command by
draw[red,line width=dr] (0:rm) arc (0:360:rm);
but then I get a non-sensical result in which the red strip is far too large:
This is not surprising given the remarks in Section 94.1.2 "Considerations concerning units" in the pgf manual (v3.1.2). What does surprise me is that simply adding cm
like this
draw[red,line width=dr] (0:rm cm) arc (0:360:rm cm);
does not work - in the sense that there is no change in the output. However, in Jake's answer, he adds pt
which seems to work (as witnessed by his comment Somehow, the [...] units got lost, so we add 'pt' at the end. Not nice...
).
So my questions are:
- Why does adding
pt
work in Jake's answer but not when I addcm
? - I cannot make sense of Section 94.1.2. There seem to be commands for checking whether units are "declared" but there do not seem to be any commands for "adding them back" to a result. What good is it to be able to check for units but not "adding them back"?
tikz-pgf pgfmath
add a comment |
This question is inspired by Jake's answer to this question. The problem is illustrated by this MWE:
documentclass{standalone}
usepackage{tikz}
begin{document}
defri{1.0cm} % define inner diameter
defro{2.0cm} % define outer diameter
begin{tikzpicture}
pgfmathsetmacro{dr}{ro-ri} % compute width
pgfmathsetmacro{rm}{(ri+ro)/2} % compute mean diameter
draw[red,line width=dr] (0:ro) arc (0:360:ro);
draw[black] (0,0) circle (ro) circle (ri);
end{tikzpicture}
end{document}
This produces the following output:
But this is not what I want, which is that the red strip should be between the two black circles. I expected that I could achieve this by replacing the first draw
command by
draw[red,line width=dr] (0:rm) arc (0:360:rm);
but then I get a non-sensical result in which the red strip is far too large:
This is not surprising given the remarks in Section 94.1.2 "Considerations concerning units" in the pgf manual (v3.1.2). What does surprise me is that simply adding cm
like this
draw[red,line width=dr] (0:rm cm) arc (0:360:rm cm);
does not work - in the sense that there is no change in the output. However, in Jake's answer, he adds pt
which seems to work (as witnessed by his comment Somehow, the [...] units got lost, so we add 'pt' at the end. Not nice...
).
So my questions are:
- Why does adding
pt
work in Jake's answer but not when I addcm
? - I cannot make sense of Section 94.1.2. There seem to be commands for checking whether units are "declared" but there do not seem to be any commands for "adding them back" to a result. What good is it to be able to check for units but not "adding them back"?
tikz-pgf pgfmath
Also check out pgfmathsetlength and pgfmathsetlengthmacro.
– John Kormylo
19 hours ago
add a comment |
This question is inspired by Jake's answer to this question. The problem is illustrated by this MWE:
documentclass{standalone}
usepackage{tikz}
begin{document}
defri{1.0cm} % define inner diameter
defro{2.0cm} % define outer diameter
begin{tikzpicture}
pgfmathsetmacro{dr}{ro-ri} % compute width
pgfmathsetmacro{rm}{(ri+ro)/2} % compute mean diameter
draw[red,line width=dr] (0:ro) arc (0:360:ro);
draw[black] (0,0) circle (ro) circle (ri);
end{tikzpicture}
end{document}
This produces the following output:
But this is not what I want, which is that the red strip should be between the two black circles. I expected that I could achieve this by replacing the first draw
command by
draw[red,line width=dr] (0:rm) arc (0:360:rm);
but then I get a non-sensical result in which the red strip is far too large:
This is not surprising given the remarks in Section 94.1.2 "Considerations concerning units" in the pgf manual (v3.1.2). What does surprise me is that simply adding cm
like this
draw[red,line width=dr] (0:rm cm) arc (0:360:rm cm);
does not work - in the sense that there is no change in the output. However, in Jake's answer, he adds pt
which seems to work (as witnessed by his comment Somehow, the [...] units got lost, so we add 'pt' at the end. Not nice...
).
So my questions are:
- Why does adding
pt
work in Jake's answer but not when I addcm
? - I cannot make sense of Section 94.1.2. There seem to be commands for checking whether units are "declared" but there do not seem to be any commands for "adding them back" to a result. What good is it to be able to check for units but not "adding them back"?
tikz-pgf pgfmath
This question is inspired by Jake's answer to this question. The problem is illustrated by this MWE:
documentclass{standalone}
usepackage{tikz}
begin{document}
defri{1.0cm} % define inner diameter
defro{2.0cm} % define outer diameter
begin{tikzpicture}
pgfmathsetmacro{dr}{ro-ri} % compute width
pgfmathsetmacro{rm}{(ri+ro)/2} % compute mean diameter
draw[red,line width=dr] (0:ro) arc (0:360:ro);
draw[black] (0,0) circle (ro) circle (ri);
end{tikzpicture}
end{document}
This produces the following output:
But this is not what I want, which is that the red strip should be between the two black circles. I expected that I could achieve this by replacing the first draw
command by
draw[red,line width=dr] (0:rm) arc (0:360:rm);
but then I get a non-sensical result in which the red strip is far too large:
This is not surprising given the remarks in Section 94.1.2 "Considerations concerning units" in the pgf manual (v3.1.2). What does surprise me is that simply adding cm
like this
draw[red,line width=dr] (0:rm cm) arc (0:360:rm cm);
does not work - in the sense that there is no change in the output. However, in Jake's answer, he adds pt
which seems to work (as witnessed by his comment Somehow, the [...] units got lost, so we add 'pt' at the end. Not nice...
).
So my questions are:
- Why does adding
pt
work in Jake's answer but not when I addcm
? - I cannot make sense of Section 94.1.2. There seem to be commands for checking whether units are "declared" but there do not seem to be any commands for "adding them back" to a result. What good is it to be able to check for units but not "adding them back"?
tikz-pgf pgfmath
tikz-pgf pgfmath
edited yesterday
user1362373
asked yesterday
user1362373user1362373
1,1021 gold badge11 silver badges28 bronze badges
1,1021 gold badge11 silver badges28 bronze badges
Also check out pgfmathsetlength and pgfmathsetlengthmacro.
– John Kormylo
19 hours ago
add a comment |
Also check out pgfmathsetlength and pgfmathsetlengthmacro.
– John Kormylo
19 hours ago
Also check out pgfmathsetlength and pgfmathsetlengthmacro.
– John Kormylo
19 hours ago
Also check out pgfmathsetlength and pgfmathsetlengthmacro.
– John Kormylo
19 hours ago
add a comment |
2 Answers
2
active
oldest
votes
pgfmathsetmacro
calculates a length and gives back the result in pt but without the unit pt attached - the macro contains simply a number. So if you want to use this number in a sensible way you should reattach the pt:
documentclass{standalone}
usepackage{tikz}
begin{document}
defri{1.0cm} % define inner diameter
defro{2.0cm} % define outer diameter
begin{tikzpicture}
pgfmathsetmacro{dr}{ro-ri} % compute width
pgfmathsetmacro{rm}{(ri+ro)/2} % compute mean diameter
showrm %<--- shows > rm=macro: ->42.67912.
draw[red,line width=dr] (0:rm pt) arc (0:360:rm pt);
draw[black] (0,0) circle (ro) circle (ri);
end{tikzpicture}
end{document}
Instead of pdfmathsetmacro
you can use pgfmathsetlengthmacro
documentclass{standalone}
usepackage{tikz}
begin{document}
defri{1.0cm} % define inner diameter
defro{2.0cm} % define outer diameter
begin{tikzpicture}
pgfmathsetlengthmacro{dr}{ro-ri} % compute width
pgfmathsetlengthmacro{rm}{(ri+ro)/2} % compute mean diameter
showrm % > rm=macro: ->42.67912pt.
draw[red,line width=dr] (0:rm) arc (0:360:rm);
draw[black] (0,0) circle (ro) circle (ri);
end{tikzpicture}
end{document}
Thanks, I get it now. Still somewhat confusing that you would need to addpt
if the arithmetic is done in pt, however.
– user1362373
18 hours ago
add a comment |
Very simple: divide or multiply by 1cm
. That way you can work in any units you like, such as cm. (I do not recommend using rm
for a macro name, though.)
documentclass{standalone}
usepackage{tikz}
begin{document}
defri{1.0cm} % define inner diameter
defro{2.0cm} % define outer diameter
begin{tikzpicture}
pgfmathsetmacro{dr}{ro-ri} % compute width
pgfmathsetmacro{rm}{(ri+ro)/2cm} % compute mean diameter
typeout{rm}
draw[red,line width=dr] (0:rm*1cm) arc (0:360:rm*1cm);
draw[black] (0,0) circle (ro) circle (ri);
end{tikzpicture}
end{document}
New contributor
That's a nice trick.
– user1362373
18 hours ago
add a comment |
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',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f504097%2fhow-to-add-units-to-results-of-pgfmathsetmacro%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
pgfmathsetmacro
calculates a length and gives back the result in pt but without the unit pt attached - the macro contains simply a number. So if you want to use this number in a sensible way you should reattach the pt:
documentclass{standalone}
usepackage{tikz}
begin{document}
defri{1.0cm} % define inner diameter
defro{2.0cm} % define outer diameter
begin{tikzpicture}
pgfmathsetmacro{dr}{ro-ri} % compute width
pgfmathsetmacro{rm}{(ri+ro)/2} % compute mean diameter
showrm %<--- shows > rm=macro: ->42.67912.
draw[red,line width=dr] (0:rm pt) arc (0:360:rm pt);
draw[black] (0,0) circle (ro) circle (ri);
end{tikzpicture}
end{document}
Instead of pdfmathsetmacro
you can use pgfmathsetlengthmacro
documentclass{standalone}
usepackage{tikz}
begin{document}
defri{1.0cm} % define inner diameter
defro{2.0cm} % define outer diameter
begin{tikzpicture}
pgfmathsetlengthmacro{dr}{ro-ri} % compute width
pgfmathsetlengthmacro{rm}{(ri+ro)/2} % compute mean diameter
showrm % > rm=macro: ->42.67912pt.
draw[red,line width=dr] (0:rm) arc (0:360:rm);
draw[black] (0,0) circle (ro) circle (ri);
end{tikzpicture}
end{document}
Thanks, I get it now. Still somewhat confusing that you would need to addpt
if the arithmetic is done in pt, however.
– user1362373
18 hours ago
add a comment |
pgfmathsetmacro
calculates a length and gives back the result in pt but without the unit pt attached - the macro contains simply a number. So if you want to use this number in a sensible way you should reattach the pt:
documentclass{standalone}
usepackage{tikz}
begin{document}
defri{1.0cm} % define inner diameter
defro{2.0cm} % define outer diameter
begin{tikzpicture}
pgfmathsetmacro{dr}{ro-ri} % compute width
pgfmathsetmacro{rm}{(ri+ro)/2} % compute mean diameter
showrm %<--- shows > rm=macro: ->42.67912.
draw[red,line width=dr] (0:rm pt) arc (0:360:rm pt);
draw[black] (0,0) circle (ro) circle (ri);
end{tikzpicture}
end{document}
Instead of pdfmathsetmacro
you can use pgfmathsetlengthmacro
documentclass{standalone}
usepackage{tikz}
begin{document}
defri{1.0cm} % define inner diameter
defro{2.0cm} % define outer diameter
begin{tikzpicture}
pgfmathsetlengthmacro{dr}{ro-ri} % compute width
pgfmathsetlengthmacro{rm}{(ri+ro)/2} % compute mean diameter
showrm % > rm=macro: ->42.67912pt.
draw[red,line width=dr] (0:rm) arc (0:360:rm);
draw[black] (0,0) circle (ro) circle (ri);
end{tikzpicture}
end{document}
Thanks, I get it now. Still somewhat confusing that you would need to addpt
if the arithmetic is done in pt, however.
– user1362373
18 hours ago
add a comment |
pgfmathsetmacro
calculates a length and gives back the result in pt but without the unit pt attached - the macro contains simply a number. So if you want to use this number in a sensible way you should reattach the pt:
documentclass{standalone}
usepackage{tikz}
begin{document}
defri{1.0cm} % define inner diameter
defro{2.0cm} % define outer diameter
begin{tikzpicture}
pgfmathsetmacro{dr}{ro-ri} % compute width
pgfmathsetmacro{rm}{(ri+ro)/2} % compute mean diameter
showrm %<--- shows > rm=macro: ->42.67912.
draw[red,line width=dr] (0:rm pt) arc (0:360:rm pt);
draw[black] (0,0) circle (ro) circle (ri);
end{tikzpicture}
end{document}
Instead of pdfmathsetmacro
you can use pgfmathsetlengthmacro
documentclass{standalone}
usepackage{tikz}
begin{document}
defri{1.0cm} % define inner diameter
defro{2.0cm} % define outer diameter
begin{tikzpicture}
pgfmathsetlengthmacro{dr}{ro-ri} % compute width
pgfmathsetlengthmacro{rm}{(ri+ro)/2} % compute mean diameter
showrm % > rm=macro: ->42.67912pt.
draw[red,line width=dr] (0:rm) arc (0:360:rm);
draw[black] (0,0) circle (ro) circle (ri);
end{tikzpicture}
end{document}
pgfmathsetmacro
calculates a length and gives back the result in pt but without the unit pt attached - the macro contains simply a number. So if you want to use this number in a sensible way you should reattach the pt:
documentclass{standalone}
usepackage{tikz}
begin{document}
defri{1.0cm} % define inner diameter
defro{2.0cm} % define outer diameter
begin{tikzpicture}
pgfmathsetmacro{dr}{ro-ri} % compute width
pgfmathsetmacro{rm}{(ri+ro)/2} % compute mean diameter
showrm %<--- shows > rm=macro: ->42.67912.
draw[red,line width=dr] (0:rm pt) arc (0:360:rm pt);
draw[black] (0,0) circle (ro) circle (ri);
end{tikzpicture}
end{document}
Instead of pdfmathsetmacro
you can use pgfmathsetlengthmacro
documentclass{standalone}
usepackage{tikz}
begin{document}
defri{1.0cm} % define inner diameter
defro{2.0cm} % define outer diameter
begin{tikzpicture}
pgfmathsetlengthmacro{dr}{ro-ri} % compute width
pgfmathsetlengthmacro{rm}{(ri+ro)/2} % compute mean diameter
showrm % > rm=macro: ->42.67912pt.
draw[red,line width=dr] (0:rm) arc (0:360:rm);
draw[black] (0,0) circle (ro) circle (ri);
end{tikzpicture}
end{document}
answered yesterday
Ulrike FischerUlrike Fischer
212k9 gold badges320 silver badges719 bronze badges
212k9 gold badges320 silver badges719 bronze badges
Thanks, I get it now. Still somewhat confusing that you would need to addpt
if the arithmetic is done in pt, however.
– user1362373
18 hours ago
add a comment |
Thanks, I get it now. Still somewhat confusing that you would need to addpt
if the arithmetic is done in pt, however.
– user1362373
18 hours ago
Thanks, I get it now. Still somewhat confusing that you would need to add
pt
if the arithmetic is done in pt, however.– user1362373
18 hours ago
Thanks, I get it now. Still somewhat confusing that you would need to add
pt
if the arithmetic is done in pt, however.– user1362373
18 hours ago
add a comment |
Very simple: divide or multiply by 1cm
. That way you can work in any units you like, such as cm. (I do not recommend using rm
for a macro name, though.)
documentclass{standalone}
usepackage{tikz}
begin{document}
defri{1.0cm} % define inner diameter
defro{2.0cm} % define outer diameter
begin{tikzpicture}
pgfmathsetmacro{dr}{ro-ri} % compute width
pgfmathsetmacro{rm}{(ri+ro)/2cm} % compute mean diameter
typeout{rm}
draw[red,line width=dr] (0:rm*1cm) arc (0:360:rm*1cm);
draw[black] (0,0) circle (ro) circle (ri);
end{tikzpicture}
end{document}
New contributor
That's a nice trick.
– user1362373
18 hours ago
add a comment |
Very simple: divide or multiply by 1cm
. That way you can work in any units you like, such as cm. (I do not recommend using rm
for a macro name, though.)
documentclass{standalone}
usepackage{tikz}
begin{document}
defri{1.0cm} % define inner diameter
defro{2.0cm} % define outer diameter
begin{tikzpicture}
pgfmathsetmacro{dr}{ro-ri} % compute width
pgfmathsetmacro{rm}{(ri+ro)/2cm} % compute mean diameter
typeout{rm}
draw[red,line width=dr] (0:rm*1cm) arc (0:360:rm*1cm);
draw[black] (0,0) circle (ro) circle (ri);
end{tikzpicture}
end{document}
New contributor
That's a nice trick.
– user1362373
18 hours ago
add a comment |
Very simple: divide or multiply by 1cm
. That way you can work in any units you like, such as cm. (I do not recommend using rm
for a macro name, though.)
documentclass{standalone}
usepackage{tikz}
begin{document}
defri{1.0cm} % define inner diameter
defro{2.0cm} % define outer diameter
begin{tikzpicture}
pgfmathsetmacro{dr}{ro-ri} % compute width
pgfmathsetmacro{rm}{(ri+ro)/2cm} % compute mean diameter
typeout{rm}
draw[red,line width=dr] (0:rm*1cm) arc (0:360:rm*1cm);
draw[black] (0,0) circle (ro) circle (ri);
end{tikzpicture}
end{document}
New contributor
Very simple: divide or multiply by 1cm
. That way you can work in any units you like, such as cm. (I do not recommend using rm
for a macro name, though.)
documentclass{standalone}
usepackage{tikz}
begin{document}
defri{1.0cm} % define inner diameter
defro{2.0cm} % define outer diameter
begin{tikzpicture}
pgfmathsetmacro{dr}{ro-ri} % compute width
pgfmathsetmacro{rm}{(ri+ro)/2cm} % compute mean diameter
typeout{rm}
draw[red,line width=dr] (0:rm*1cm) arc (0:360:rm*1cm);
draw[black] (0,0) circle (ro) circle (ri);
end{tikzpicture}
end{document}
New contributor
New contributor
answered 19 hours ago
HamanostorosHamanostoros
761 bronze badge
761 bronze badge
New contributor
New contributor
That's a nice trick.
– user1362373
18 hours ago
add a comment |
That's a nice trick.
– user1362373
18 hours ago
That's a nice trick.
– user1362373
18 hours ago
That's a nice trick.
– user1362373
18 hours ago
add a comment |
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f504097%2fhow-to-add-units-to-results-of-pgfmathsetmacro%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Also check out pgfmathsetlength and pgfmathsetlengthmacro.
– John Kormylo
19 hours ago