Adding width of text to node coordinate?
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I am currently trying to position some text in the center of a square drawn in a tikzpicture
, like so:
However, I am having a bit of trouble.
Take the following example:
documentclassarticle
usepackage[utf8]inputenc
usepackagegraphicx
usepackagetikzpagenodes
usepackagetikz
usepackagecalc
usepackagelayouts
begindocument
begintikzpicture[overlay, remember picture, x=1cm, y=1cm]
newcommandboxWidth5cm;
newcommandboxHeight3cm;
newcommandboxPosX5cm;
newcommandboxPosY-5cm;
newcommandsomeTextHello World;
newcommandtextPosXboxPosX + (printinunitsofcmwidthofsomeText/2);
newcommandtextPosYboxPosY + boxHeight / 2;
draw [line width=0.05cm, rounded corners=.3cm, color=red] (boxPosX,boxPosY) rectangle ++(boxWidth, boxHeight);
node at (textPosX, textPosY) someText;
endtikzpicture
enddocument
The problem arrises when I try using the width of the text: widthofsomeText/2
(from the calc
package). (Reference Post)
According to the same reference post, widthof
returns a length in points, which is incompatible with centimeters. Therefore, I tried converting to centimeters by using the method described here: printinunitsofcmwidthofsomeText
.
However, this still yields an "Illegal unit of measure (pt inserted)."
What am I doing wrong and how can I correctly convert my units from points to centimeters?
tikz-pgf positioning calculations unit-of-measure
New contributor
add a comment |Â
up vote
1
down vote
favorite
I am currently trying to position some text in the center of a square drawn in a tikzpicture
, like so:
However, I am having a bit of trouble.
Take the following example:
documentclassarticle
usepackage[utf8]inputenc
usepackagegraphicx
usepackagetikzpagenodes
usepackagetikz
usepackagecalc
usepackagelayouts
begindocument
begintikzpicture[overlay, remember picture, x=1cm, y=1cm]
newcommandboxWidth5cm;
newcommandboxHeight3cm;
newcommandboxPosX5cm;
newcommandboxPosY-5cm;
newcommandsomeTextHello World;
newcommandtextPosXboxPosX + (printinunitsofcmwidthofsomeText/2);
newcommandtextPosYboxPosY + boxHeight / 2;
draw [line width=0.05cm, rounded corners=.3cm, color=red] (boxPosX,boxPosY) rectangle ++(boxWidth, boxHeight);
node at (textPosX, textPosY) someText;
endtikzpicture
enddocument
The problem arrises when I try using the width of the text: widthofsomeText/2
(from the calc
package). (Reference Post)
According to the same reference post, widthof
returns a length in points, which is incompatible with centimeters. Therefore, I tried converting to centimeters by using the method described here: printinunitsofcmwidthofsomeText
.
However, this still yields an "Illegal unit of measure (pt inserted)."
What am I doing wrong and how can I correctly convert my units from points to centimeters?
tikz-pgf positioning calculations unit-of-measure
New contributor
can you provide a sketch of your desired result. is behind thistikzpicture
something which require so complicated code?
â Zarko
36 mins ago
1
You cannot do computations withnewcommand
, usepgfmathsetmacro
instead, e.g.pgfmathsetmacrotextPosXboxPosX + width("someText")*1pt/2cm;
. But this is absolutely unnecessary here, as far as I can see.
â marmot
35 mins ago
@Zarko I added a picture to help convey what I want.
â Dan Hoynoski
29 mins ago
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am currently trying to position some text in the center of a square drawn in a tikzpicture
, like so:
However, I am having a bit of trouble.
Take the following example:
documentclassarticle
usepackage[utf8]inputenc
usepackagegraphicx
usepackagetikzpagenodes
usepackagetikz
usepackagecalc
usepackagelayouts
begindocument
begintikzpicture[overlay, remember picture, x=1cm, y=1cm]
newcommandboxWidth5cm;
newcommandboxHeight3cm;
newcommandboxPosX5cm;
newcommandboxPosY-5cm;
newcommandsomeTextHello World;
newcommandtextPosXboxPosX + (printinunitsofcmwidthofsomeText/2);
newcommandtextPosYboxPosY + boxHeight / 2;
draw [line width=0.05cm, rounded corners=.3cm, color=red] (boxPosX,boxPosY) rectangle ++(boxWidth, boxHeight);
node at (textPosX, textPosY) someText;
endtikzpicture
enddocument
The problem arrises when I try using the width of the text: widthofsomeText/2
(from the calc
package). (Reference Post)
According to the same reference post, widthof
returns a length in points, which is incompatible with centimeters. Therefore, I tried converting to centimeters by using the method described here: printinunitsofcmwidthofsomeText
.
However, this still yields an "Illegal unit of measure (pt inserted)."
What am I doing wrong and how can I correctly convert my units from points to centimeters?
tikz-pgf positioning calculations unit-of-measure
New contributor
I am currently trying to position some text in the center of a square drawn in a tikzpicture
, like so:
However, I am having a bit of trouble.
Take the following example:
documentclassarticle
usepackage[utf8]inputenc
usepackagegraphicx
usepackagetikzpagenodes
usepackagetikz
usepackagecalc
usepackagelayouts
begindocument
begintikzpicture[overlay, remember picture, x=1cm, y=1cm]
newcommandboxWidth5cm;
newcommandboxHeight3cm;
newcommandboxPosX5cm;
newcommandboxPosY-5cm;
newcommandsomeTextHello World;
newcommandtextPosXboxPosX + (printinunitsofcmwidthofsomeText/2);
newcommandtextPosYboxPosY + boxHeight / 2;
draw [line width=0.05cm, rounded corners=.3cm, color=red] (boxPosX,boxPosY) rectangle ++(boxWidth, boxHeight);
node at (textPosX, textPosY) someText;
endtikzpicture
enddocument
The problem arrises when I try using the width of the text: widthofsomeText/2
(from the calc
package). (Reference Post)
According to the same reference post, widthof
returns a length in points, which is incompatible with centimeters. Therefore, I tried converting to centimeters by using the method described here: printinunitsofcmwidthofsomeText
.
However, this still yields an "Illegal unit of measure (pt inserted)."
What am I doing wrong and how can I correctly convert my units from points to centimeters?
tikz-pgf positioning calculations unit-of-measure
tikz-pgf positioning calculations unit-of-measure
New contributor
New contributor
edited 29 mins ago
New contributor
asked 44 mins ago
Dan Hoynoski
1255
1255
New contributor
New contributor
can you provide a sketch of your desired result. is behind thistikzpicture
something which require so complicated code?
â Zarko
36 mins ago
1
You cannot do computations withnewcommand
, usepgfmathsetmacro
instead, e.g.pgfmathsetmacrotextPosXboxPosX + width("someText")*1pt/2cm;
. But this is absolutely unnecessary here, as far as I can see.
â marmot
35 mins ago
@Zarko I added a picture to help convey what I want.
â Dan Hoynoski
29 mins ago
add a comment |Â
can you provide a sketch of your desired result. is behind thistikzpicture
something which require so complicated code?
â Zarko
36 mins ago
1
You cannot do computations withnewcommand
, usepgfmathsetmacro
instead, e.g.pgfmathsetmacrotextPosXboxPosX + width("someText")*1pt/2cm;
. But this is absolutely unnecessary here, as far as I can see.
â marmot
35 mins ago
@Zarko I added a picture to help convey what I want.
â Dan Hoynoski
29 mins ago
can you provide a sketch of your desired result. is behind this
tikzpicture
something which require so complicated code?â Zarko
36 mins ago
can you provide a sketch of your desired result. is behind this
tikzpicture
something which require so complicated code?â Zarko
36 mins ago
1
1
You cannot do computations with
newcommand
, use pgfmathsetmacro
instead, e.g. pgfmathsetmacrotextPosXboxPosX + width("someText")*1pt/2cm;
. But this is absolutely unnecessary here, as far as I can see.â marmot
35 mins ago
You cannot do computations with
newcommand
, use pgfmathsetmacro
instead, e.g. pgfmathsetmacrotextPosXboxPosX + width("someText")*1pt/2cm;
. But this is absolutely unnecessary here, as far as I can see.â marmot
35 mins ago
@Zarko I added a picture to help convey what I want.
â Dan Hoynoski
29 mins ago
@Zarko I added a picture to help convey what I want.
â Dan Hoynoski
29 mins ago
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
3
down vote
accepted
From your code I sort of sense what you might want:
documentclassarticle
usepackage[utf8]inputenc
usepackagetikzpagenodes
usepackagecalc
usepackagelayouts
begindocument
begintikzpicture[overlay, remember picture, x=1cm, y=1cm]
newcommandboxWidth5cm;
newcommandboxHeight3cm;
newcommandboxPosX5cm;
newcommandboxPosY-5cm;
newcommandsomeTextHello World;
node[draw,line width=0.05cm, rounded corners=.3cm, color=red,
minimum width=boxWidth,minimum height=boxHeight,text=black] at
(boxPosX,boxPosY) someText;
endtikzpicture
enddocument
Instead of newcommand
use pgfmathsetmacro
to do computations, e.g. pgfmathsetmacrotextPosXboxPosX + width("someText")*1pt/2cm;
. However, I think that all the complicated computations are unnecessary here. To put a text in the center of a box, it suffices to say node[draw]text
. And then you can do all sorts of spirifankerln like adding a minimum width
, rounded corners
etc.
Why can I do that addition in my new command fortextPosY
, but I cannot do more complex computation? Why doesnewcommand
allows some computation?
â Dan Hoynoski
26 mins ago
And I need something complex like this, because I will have several rectangles of the same size, each of which will have a unique string in them. The node method contours around the text only and adding redundant spaces is messy in my opinion.
â Dan Hoynoski
24 mins ago
@DanHoynoskinewcommand
by itself does not allow for computations. You're loading thecalc
package (which is not to be confused with the TikZ library of the same name), which allows you to do computations, but I guess once you load TikZ, this is sort of obsolete. And no, you can put pretty much anything inside a node oftikzpicture
, graphics, equations... (just not tikzpictures, at least you shouldn't). There are tons of libraries which allow you to arrage rectangles of the same size, e.g.matrix
orchains
.
â marmot
22 mins ago
you are absolutely correct! Using a node is so much better. And that is strange, because if you settextPosX
toboxPosX
in my original code above (to prevent that conversion error) and then it compiles just fine even withboxPosY + boxHeight / 2
being there. Are you say that because I am loading the calc package, it added this ability tonewcommand
?
â Dan Hoynoski
8 mins ago
1
@DanHoynoski No, calc does not do any magic of that kind. It is TikZ which starts to parse these things and then sees "Oh, here is somex+y
, let's add them." You can always check such things by saying e.g.typeoutboxPosX
and the you will see whether this is the stringx+y
or the sum.
â marmot
4 mins ago
 |Â
show 2 more comments
up vote
3
down vote
If the text is to be placed in the centre of the rectangle, simply place it with a node midway
down the path.
draw [line width=0.05cm, rounded corners=.3cm, color=red]
(boxPosX,boxPosY) rectangle ++(boxWidth, boxHeight)node[midway,text=black]someText;
documentclassarticle
usepackage[utf8]inputenc
usepackagegraphicx
usepackagetikzpagenodes
usepackagetikz
usepackagecalc
usepackagelayouts
begindocument
begintikzpicture[overlay, remember picture, x=1cm, y=1cm]
newcommandboxWidth5cm;
newcommandboxHeight3cm;
newcommandboxPosX5cm;
newcommandboxPosY-5cm;
newcommandsomeTextHello World;
%newcommandtextPosXboxPosX + (printinunitsofcmwidthofsomeText/2);
%newcommandtextPosYboxPosY + boxHeight / 2;
draw [line width=0.05cm, rounded corners=.3cm, color=red]
(boxPosX,boxPosY) rectangle ++(boxWidth, boxHeight)node[midway,text=black]someText;
endtikzpicture
enddocument
I appreciate your answer! I did not think about adding another node like this! If I could accept two answers, I would!
â Dan Hoynoski
6 mins ago
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
From your code I sort of sense what you might want:
documentclassarticle
usepackage[utf8]inputenc
usepackagetikzpagenodes
usepackagecalc
usepackagelayouts
begindocument
begintikzpicture[overlay, remember picture, x=1cm, y=1cm]
newcommandboxWidth5cm;
newcommandboxHeight3cm;
newcommandboxPosX5cm;
newcommandboxPosY-5cm;
newcommandsomeTextHello World;
node[draw,line width=0.05cm, rounded corners=.3cm, color=red,
minimum width=boxWidth,minimum height=boxHeight,text=black] at
(boxPosX,boxPosY) someText;
endtikzpicture
enddocument
Instead of newcommand
use pgfmathsetmacro
to do computations, e.g. pgfmathsetmacrotextPosXboxPosX + width("someText")*1pt/2cm;
. However, I think that all the complicated computations are unnecessary here. To put a text in the center of a box, it suffices to say node[draw]text
. And then you can do all sorts of spirifankerln like adding a minimum width
, rounded corners
etc.
Why can I do that addition in my new command fortextPosY
, but I cannot do more complex computation? Why doesnewcommand
allows some computation?
â Dan Hoynoski
26 mins ago
And I need something complex like this, because I will have several rectangles of the same size, each of which will have a unique string in them. The node method contours around the text only and adding redundant spaces is messy in my opinion.
â Dan Hoynoski
24 mins ago
@DanHoynoskinewcommand
by itself does not allow for computations. You're loading thecalc
package (which is not to be confused with the TikZ library of the same name), which allows you to do computations, but I guess once you load TikZ, this is sort of obsolete. And no, you can put pretty much anything inside a node oftikzpicture
, graphics, equations... (just not tikzpictures, at least you shouldn't). There are tons of libraries which allow you to arrage rectangles of the same size, e.g.matrix
orchains
.
â marmot
22 mins ago
you are absolutely correct! Using a node is so much better. And that is strange, because if you settextPosX
toboxPosX
in my original code above (to prevent that conversion error) and then it compiles just fine even withboxPosY + boxHeight / 2
being there. Are you say that because I am loading the calc package, it added this ability tonewcommand
?
â Dan Hoynoski
8 mins ago
1
@DanHoynoski No, calc does not do any magic of that kind. It is TikZ which starts to parse these things and then sees "Oh, here is somex+y
, let's add them." You can always check such things by saying e.g.typeoutboxPosX
and the you will see whether this is the stringx+y
or the sum.
â marmot
4 mins ago
 |Â
show 2 more comments
up vote
3
down vote
accepted
From your code I sort of sense what you might want:
documentclassarticle
usepackage[utf8]inputenc
usepackagetikzpagenodes
usepackagecalc
usepackagelayouts
begindocument
begintikzpicture[overlay, remember picture, x=1cm, y=1cm]
newcommandboxWidth5cm;
newcommandboxHeight3cm;
newcommandboxPosX5cm;
newcommandboxPosY-5cm;
newcommandsomeTextHello World;
node[draw,line width=0.05cm, rounded corners=.3cm, color=red,
minimum width=boxWidth,minimum height=boxHeight,text=black] at
(boxPosX,boxPosY) someText;
endtikzpicture
enddocument
Instead of newcommand
use pgfmathsetmacro
to do computations, e.g. pgfmathsetmacrotextPosXboxPosX + width("someText")*1pt/2cm;
. However, I think that all the complicated computations are unnecessary here. To put a text in the center of a box, it suffices to say node[draw]text
. And then you can do all sorts of spirifankerln like adding a minimum width
, rounded corners
etc.
Why can I do that addition in my new command fortextPosY
, but I cannot do more complex computation? Why doesnewcommand
allows some computation?
â Dan Hoynoski
26 mins ago
And I need something complex like this, because I will have several rectangles of the same size, each of which will have a unique string in them. The node method contours around the text only and adding redundant spaces is messy in my opinion.
â Dan Hoynoski
24 mins ago
@DanHoynoskinewcommand
by itself does not allow for computations. You're loading thecalc
package (which is not to be confused with the TikZ library of the same name), which allows you to do computations, but I guess once you load TikZ, this is sort of obsolete. And no, you can put pretty much anything inside a node oftikzpicture
, graphics, equations... (just not tikzpictures, at least you shouldn't). There are tons of libraries which allow you to arrage rectangles of the same size, e.g.matrix
orchains
.
â marmot
22 mins ago
you are absolutely correct! Using a node is so much better. And that is strange, because if you settextPosX
toboxPosX
in my original code above (to prevent that conversion error) and then it compiles just fine even withboxPosY + boxHeight / 2
being there. Are you say that because I am loading the calc package, it added this ability tonewcommand
?
â Dan Hoynoski
8 mins ago
1
@DanHoynoski No, calc does not do any magic of that kind. It is TikZ which starts to parse these things and then sees "Oh, here is somex+y
, let's add them." You can always check such things by saying e.g.typeoutboxPosX
and the you will see whether this is the stringx+y
or the sum.
â marmot
4 mins ago
 |Â
show 2 more comments
up vote
3
down vote
accepted
up vote
3
down vote
accepted
From your code I sort of sense what you might want:
documentclassarticle
usepackage[utf8]inputenc
usepackagetikzpagenodes
usepackagecalc
usepackagelayouts
begindocument
begintikzpicture[overlay, remember picture, x=1cm, y=1cm]
newcommandboxWidth5cm;
newcommandboxHeight3cm;
newcommandboxPosX5cm;
newcommandboxPosY-5cm;
newcommandsomeTextHello World;
node[draw,line width=0.05cm, rounded corners=.3cm, color=red,
minimum width=boxWidth,minimum height=boxHeight,text=black] at
(boxPosX,boxPosY) someText;
endtikzpicture
enddocument
Instead of newcommand
use pgfmathsetmacro
to do computations, e.g. pgfmathsetmacrotextPosXboxPosX + width("someText")*1pt/2cm;
. However, I think that all the complicated computations are unnecessary here. To put a text in the center of a box, it suffices to say node[draw]text
. And then you can do all sorts of spirifankerln like adding a minimum width
, rounded corners
etc.
From your code I sort of sense what you might want:
documentclassarticle
usepackage[utf8]inputenc
usepackagetikzpagenodes
usepackagecalc
usepackagelayouts
begindocument
begintikzpicture[overlay, remember picture, x=1cm, y=1cm]
newcommandboxWidth5cm;
newcommandboxHeight3cm;
newcommandboxPosX5cm;
newcommandboxPosY-5cm;
newcommandsomeTextHello World;
node[draw,line width=0.05cm, rounded corners=.3cm, color=red,
minimum width=boxWidth,minimum height=boxHeight,text=black] at
(boxPosX,boxPosY) someText;
endtikzpicture
enddocument
Instead of newcommand
use pgfmathsetmacro
to do computations, e.g. pgfmathsetmacrotextPosXboxPosX + width("someText")*1pt/2cm;
. However, I think that all the complicated computations are unnecessary here. To put a text in the center of a box, it suffices to say node[draw]text
. And then you can do all sorts of spirifankerln like adding a minimum width
, rounded corners
etc.
answered 29 mins ago
marmot
64.1k470139
64.1k470139
Why can I do that addition in my new command fortextPosY
, but I cannot do more complex computation? Why doesnewcommand
allows some computation?
â Dan Hoynoski
26 mins ago
And I need something complex like this, because I will have several rectangles of the same size, each of which will have a unique string in them. The node method contours around the text only and adding redundant spaces is messy in my opinion.
â Dan Hoynoski
24 mins ago
@DanHoynoskinewcommand
by itself does not allow for computations. You're loading thecalc
package (which is not to be confused with the TikZ library of the same name), which allows you to do computations, but I guess once you load TikZ, this is sort of obsolete. And no, you can put pretty much anything inside a node oftikzpicture
, graphics, equations... (just not tikzpictures, at least you shouldn't). There are tons of libraries which allow you to arrage rectangles of the same size, e.g.matrix
orchains
.
â marmot
22 mins ago
you are absolutely correct! Using a node is so much better. And that is strange, because if you settextPosX
toboxPosX
in my original code above (to prevent that conversion error) and then it compiles just fine even withboxPosY + boxHeight / 2
being there. Are you say that because I am loading the calc package, it added this ability tonewcommand
?
â Dan Hoynoski
8 mins ago
1
@DanHoynoski No, calc does not do any magic of that kind. It is TikZ which starts to parse these things and then sees "Oh, here is somex+y
, let's add them." You can always check such things by saying e.g.typeoutboxPosX
and the you will see whether this is the stringx+y
or the sum.
â marmot
4 mins ago
 |Â
show 2 more comments
Why can I do that addition in my new command fortextPosY
, but I cannot do more complex computation? Why doesnewcommand
allows some computation?
â Dan Hoynoski
26 mins ago
And I need something complex like this, because I will have several rectangles of the same size, each of which will have a unique string in them. The node method contours around the text only and adding redundant spaces is messy in my opinion.
â Dan Hoynoski
24 mins ago
@DanHoynoskinewcommand
by itself does not allow for computations. You're loading thecalc
package (which is not to be confused with the TikZ library of the same name), which allows you to do computations, but I guess once you load TikZ, this is sort of obsolete. And no, you can put pretty much anything inside a node oftikzpicture
, graphics, equations... (just not tikzpictures, at least you shouldn't). There are tons of libraries which allow you to arrage rectangles of the same size, e.g.matrix
orchains
.
â marmot
22 mins ago
you are absolutely correct! Using a node is so much better. And that is strange, because if you settextPosX
toboxPosX
in my original code above (to prevent that conversion error) and then it compiles just fine even withboxPosY + boxHeight / 2
being there. Are you say that because I am loading the calc package, it added this ability tonewcommand
?
â Dan Hoynoski
8 mins ago
1
@DanHoynoski No, calc does not do any magic of that kind. It is TikZ which starts to parse these things and then sees "Oh, here is somex+y
, let's add them." You can always check such things by saying e.g.typeoutboxPosX
and the you will see whether this is the stringx+y
or the sum.
â marmot
4 mins ago
Why can I do that addition in my new command for
textPosY
, but I cannot do more complex computation? Why does newcommand
allows some computation?â Dan Hoynoski
26 mins ago
Why can I do that addition in my new command for
textPosY
, but I cannot do more complex computation? Why does newcommand
allows some computation?â Dan Hoynoski
26 mins ago
And I need something complex like this, because I will have several rectangles of the same size, each of which will have a unique string in them. The node method contours around the text only and adding redundant spaces is messy in my opinion.
â Dan Hoynoski
24 mins ago
And I need something complex like this, because I will have several rectangles of the same size, each of which will have a unique string in them. The node method contours around the text only and adding redundant spaces is messy in my opinion.
â Dan Hoynoski
24 mins ago
@DanHoynoski
newcommand
by itself does not allow for computations. You're loading the calc
package (which is not to be confused with the TikZ library of the same name), which allows you to do computations, but I guess once you load TikZ, this is sort of obsolete. And no, you can put pretty much anything inside a node of tikzpicture
, graphics, equations... (just not tikzpictures, at least you shouldn't). There are tons of libraries which allow you to arrage rectangles of the same size, e.g. matrix
or chains
.â marmot
22 mins ago
@DanHoynoski
newcommand
by itself does not allow for computations. You're loading the calc
package (which is not to be confused with the TikZ library of the same name), which allows you to do computations, but I guess once you load TikZ, this is sort of obsolete. And no, you can put pretty much anything inside a node of tikzpicture
, graphics, equations... (just not tikzpictures, at least you shouldn't). There are tons of libraries which allow you to arrage rectangles of the same size, e.g. matrix
or chains
.â marmot
22 mins ago
you are absolutely correct! Using a node is so much better. And that is strange, because if you set
textPosX
to boxPosX
in my original code above (to prevent that conversion error) and then it compiles just fine even with boxPosY + boxHeight / 2
being there. Are you say that because I am loading the calc package, it added this ability to newcommand
?â Dan Hoynoski
8 mins ago
you are absolutely correct! Using a node is so much better. And that is strange, because if you set
textPosX
to boxPosX
in my original code above (to prevent that conversion error) and then it compiles just fine even with boxPosY + boxHeight / 2
being there. Are you say that because I am loading the calc package, it added this ability to newcommand
?â Dan Hoynoski
8 mins ago
1
1
@DanHoynoski No, calc does not do any magic of that kind. It is TikZ which starts to parse these things and then sees "Oh, here is some
x+y
, let's add them." You can always check such things by saying e.g. typeoutboxPosX
and the you will see whether this is the string x+y
or the sum.â marmot
4 mins ago
@DanHoynoski No, calc does not do any magic of that kind. It is TikZ which starts to parse these things and then sees "Oh, here is some
x+y
, let's add them." You can always check such things by saying e.g. typeoutboxPosX
and the you will see whether this is the string x+y
or the sum.â marmot
4 mins ago
 |Â
show 2 more comments
up vote
3
down vote
If the text is to be placed in the centre of the rectangle, simply place it with a node midway
down the path.
draw [line width=0.05cm, rounded corners=.3cm, color=red]
(boxPosX,boxPosY) rectangle ++(boxWidth, boxHeight)node[midway,text=black]someText;
documentclassarticle
usepackage[utf8]inputenc
usepackagegraphicx
usepackagetikzpagenodes
usepackagetikz
usepackagecalc
usepackagelayouts
begindocument
begintikzpicture[overlay, remember picture, x=1cm, y=1cm]
newcommandboxWidth5cm;
newcommandboxHeight3cm;
newcommandboxPosX5cm;
newcommandboxPosY-5cm;
newcommandsomeTextHello World;
%newcommandtextPosXboxPosX + (printinunitsofcmwidthofsomeText/2);
%newcommandtextPosYboxPosY + boxHeight / 2;
draw [line width=0.05cm, rounded corners=.3cm, color=red]
(boxPosX,boxPosY) rectangle ++(boxWidth, boxHeight)node[midway,text=black]someText;
endtikzpicture
enddocument
I appreciate your answer! I did not think about adding another node like this! If I could accept two answers, I would!
â Dan Hoynoski
6 mins ago
add a comment |Â
up vote
3
down vote
If the text is to be placed in the centre of the rectangle, simply place it with a node midway
down the path.
draw [line width=0.05cm, rounded corners=.3cm, color=red]
(boxPosX,boxPosY) rectangle ++(boxWidth, boxHeight)node[midway,text=black]someText;
documentclassarticle
usepackage[utf8]inputenc
usepackagegraphicx
usepackagetikzpagenodes
usepackagetikz
usepackagecalc
usepackagelayouts
begindocument
begintikzpicture[overlay, remember picture, x=1cm, y=1cm]
newcommandboxWidth5cm;
newcommandboxHeight3cm;
newcommandboxPosX5cm;
newcommandboxPosY-5cm;
newcommandsomeTextHello World;
%newcommandtextPosXboxPosX + (printinunitsofcmwidthofsomeText/2);
%newcommandtextPosYboxPosY + boxHeight / 2;
draw [line width=0.05cm, rounded corners=.3cm, color=red]
(boxPosX,boxPosY) rectangle ++(boxWidth, boxHeight)node[midway,text=black]someText;
endtikzpicture
enddocument
I appreciate your answer! I did not think about adding another node like this! If I could accept two answers, I would!
â Dan Hoynoski
6 mins ago
add a comment |Â
up vote
3
down vote
up vote
3
down vote
If the text is to be placed in the centre of the rectangle, simply place it with a node midway
down the path.
draw [line width=0.05cm, rounded corners=.3cm, color=red]
(boxPosX,boxPosY) rectangle ++(boxWidth, boxHeight)node[midway,text=black]someText;
documentclassarticle
usepackage[utf8]inputenc
usepackagegraphicx
usepackagetikzpagenodes
usepackagetikz
usepackagecalc
usepackagelayouts
begindocument
begintikzpicture[overlay, remember picture, x=1cm, y=1cm]
newcommandboxWidth5cm;
newcommandboxHeight3cm;
newcommandboxPosX5cm;
newcommandboxPosY-5cm;
newcommandsomeTextHello World;
%newcommandtextPosXboxPosX + (printinunitsofcmwidthofsomeText/2);
%newcommandtextPosYboxPosY + boxHeight / 2;
draw [line width=0.05cm, rounded corners=.3cm, color=red]
(boxPosX,boxPosY) rectangle ++(boxWidth, boxHeight)node[midway,text=black]someText;
endtikzpicture
enddocument
If the text is to be placed in the centre of the rectangle, simply place it with a node midway
down the path.
draw [line width=0.05cm, rounded corners=.3cm, color=red]
(boxPosX,boxPosY) rectangle ++(boxWidth, boxHeight)node[midway,text=black]someText;
documentclassarticle
usepackage[utf8]inputenc
usepackagegraphicx
usepackagetikzpagenodes
usepackagetikz
usepackagecalc
usepackagelayouts
begindocument
begintikzpicture[overlay, remember picture, x=1cm, y=1cm]
newcommandboxWidth5cm;
newcommandboxHeight3cm;
newcommandboxPosX5cm;
newcommandboxPosY-5cm;
newcommandsomeTextHello World;
%newcommandtextPosXboxPosX + (printinunitsofcmwidthofsomeText/2);
%newcommandtextPosYboxPosY + boxHeight / 2;
draw [line width=0.05cm, rounded corners=.3cm, color=red]
(boxPosX,boxPosY) rectangle ++(boxWidth, boxHeight)node[midway,text=black]someText;
endtikzpicture
enddocument
answered 19 mins ago
AndréC
3,566729
3,566729
I appreciate your answer! I did not think about adding another node like this! If I could accept two answers, I would!
â Dan Hoynoski
6 mins ago
add a comment |Â
I appreciate your answer! I did not think about adding another node like this! If I could accept two answers, I would!
â Dan Hoynoski
6 mins ago
I appreciate your answer! I did not think about adding another node like this! If I could accept two answers, I would!
â Dan Hoynoski
6 mins ago
I appreciate your answer! I did not think about adding another node like this! If I could accept two answers, I would!
â Dan Hoynoski
6 mins ago
add a comment |Â
Dan Hoynoski is a new contributor. Be nice, and check out our Code of Conduct.
Dan Hoynoski is a new contributor. Be nice, and check out our Code of Conduct.
Dan Hoynoski is a new contributor. Be nice, and check out our Code of Conduct.
Dan Hoynoski 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%2f454546%2fadding-width-of-text-to-node-coordinate%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
can you provide a sketch of your desired result. is behind this
tikzpicture
something which require so complicated code?â Zarko
36 mins ago
1
You cannot do computations with
newcommand
, usepgfmathsetmacro
instead, e.g.pgfmathsetmacrotextPosXboxPosX + width("someText")*1pt/2cm;
. But this is absolutely unnecessary here, as far as I can see.â marmot
35 mins ago
@Zarko I added a picture to help convey what I want.
â Dan Hoynoski
29 mins ago