Globally configure length units in TikZ
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
Consider the following MWE:
documentclassstandalone
usepackagetikz
usetikzlibrarypositioning
begindocument
tikzset
x = 1cm,
y = 1cm,
node distance = 2,
auto,
on grid,
test/.style =
draw,
circle,
inner sep = 0pt,
semithick,
minimum width = 0.5,
,
box/.style =
draw,
rectangle,
minimum width = 1,
minimum height = 1,
inner sep = 0pt,
,
begintikzpicture
node (node1) at (0,0) [label=right:test, test] ;
node (node2) [below=of node1, label=right:box, box] ;
node (node3) [right=of node1, label=right:test, test, minimum width = 0.5cm] ;
node (node4) [below=of node3, label=right:box, box, minimum width = 1cm, minimum height = 1cm] ;
endtikzpicture
enddocument
In the first two lines of the tikzset
statement, I want to set the measurement units to be 1cm, so, according to my oppinion, the test
node should be 0.5cm in width (and height, because it is a circle), and the box
node should have a side length of 1cm each. However, if we look at the result of the above code
we can clearly see that
a) the nodes seem to be positioned correctly, the appear like there is a 2cm distance between them, as expected;
b) the size of the left two nodes is wrong - I would expect the left two nodes to have the same size as the right two ones, but this isn't the case.
How shall I change my tikzset
code to have the correct sizes of the left two nodes? I don't want to use something like
test/.style =
draw,
circle,
inner sep = 0pt,
semithick,
minimum width = 0.5cm,
,
because I want the node sizes be relative to the node distances and relative to each other. If I would use absolute widths and heights within the style definitions for the nodes, this would be rather unflexible, so I wonder whether it is possible to set the length of "1 unit".
tikz-pgf tikz-styles
add a comment |Â
up vote
3
down vote
favorite
Consider the following MWE:
documentclassstandalone
usepackagetikz
usetikzlibrarypositioning
begindocument
tikzset
x = 1cm,
y = 1cm,
node distance = 2,
auto,
on grid,
test/.style =
draw,
circle,
inner sep = 0pt,
semithick,
minimum width = 0.5,
,
box/.style =
draw,
rectangle,
minimum width = 1,
minimum height = 1,
inner sep = 0pt,
,
begintikzpicture
node (node1) at (0,0) [label=right:test, test] ;
node (node2) [below=of node1, label=right:box, box] ;
node (node3) [right=of node1, label=right:test, test, minimum width = 0.5cm] ;
node (node4) [below=of node3, label=right:box, box, minimum width = 1cm, minimum height = 1cm] ;
endtikzpicture
enddocument
In the first two lines of the tikzset
statement, I want to set the measurement units to be 1cm, so, according to my oppinion, the test
node should be 0.5cm in width (and height, because it is a circle), and the box
node should have a side length of 1cm each. However, if we look at the result of the above code
we can clearly see that
a) the nodes seem to be positioned correctly, the appear like there is a 2cm distance between them, as expected;
b) the size of the left two nodes is wrong - I would expect the left two nodes to have the same size as the right two ones, but this isn't the case.
How shall I change my tikzset
code to have the correct sizes of the left two nodes? I don't want to use something like
test/.style =
draw,
circle,
inner sep = 0pt,
semithick,
minimum width = 0.5cm,
,
because I want the node sizes be relative to the node distances and relative to each other. If I would use absolute widths and heights within the style definitions for the nodes, this would be rather unflexible, so I wonder whether it is possible to set the length of "1 unit".
tikz-pgf tikz-styles
yes I know. But I don't want to use units, as I said - instead I want relative lengths. I.e. the width shall be 1/2 of the node distance and so on.
– T. Pluess
1 hour ago
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
Consider the following MWE:
documentclassstandalone
usepackagetikz
usetikzlibrarypositioning
begindocument
tikzset
x = 1cm,
y = 1cm,
node distance = 2,
auto,
on grid,
test/.style =
draw,
circle,
inner sep = 0pt,
semithick,
minimum width = 0.5,
,
box/.style =
draw,
rectangle,
minimum width = 1,
minimum height = 1,
inner sep = 0pt,
,
begintikzpicture
node (node1) at (0,0) [label=right:test, test] ;
node (node2) [below=of node1, label=right:box, box] ;
node (node3) [right=of node1, label=right:test, test, minimum width = 0.5cm] ;
node (node4) [below=of node3, label=right:box, box, minimum width = 1cm, minimum height = 1cm] ;
endtikzpicture
enddocument
In the first two lines of the tikzset
statement, I want to set the measurement units to be 1cm, so, according to my oppinion, the test
node should be 0.5cm in width (and height, because it is a circle), and the box
node should have a side length of 1cm each. However, if we look at the result of the above code
we can clearly see that
a) the nodes seem to be positioned correctly, the appear like there is a 2cm distance between them, as expected;
b) the size of the left two nodes is wrong - I would expect the left two nodes to have the same size as the right two ones, but this isn't the case.
How shall I change my tikzset
code to have the correct sizes of the left two nodes? I don't want to use something like
test/.style =
draw,
circle,
inner sep = 0pt,
semithick,
minimum width = 0.5cm,
,
because I want the node sizes be relative to the node distances and relative to each other. If I would use absolute widths and heights within the style definitions for the nodes, this would be rather unflexible, so I wonder whether it is possible to set the length of "1 unit".
tikz-pgf tikz-styles
Consider the following MWE:
documentclassstandalone
usepackagetikz
usetikzlibrarypositioning
begindocument
tikzset
x = 1cm,
y = 1cm,
node distance = 2,
auto,
on grid,
test/.style =
draw,
circle,
inner sep = 0pt,
semithick,
minimum width = 0.5,
,
box/.style =
draw,
rectangle,
minimum width = 1,
minimum height = 1,
inner sep = 0pt,
,
begintikzpicture
node (node1) at (0,0) [label=right:test, test] ;
node (node2) [below=of node1, label=right:box, box] ;
node (node3) [right=of node1, label=right:test, test, minimum width = 0.5cm] ;
node (node4) [below=of node3, label=right:box, box, minimum width = 1cm, minimum height = 1cm] ;
endtikzpicture
enddocument
In the first two lines of the tikzset
statement, I want to set the measurement units to be 1cm, so, according to my oppinion, the test
node should be 0.5cm in width (and height, because it is a circle), and the box
node should have a side length of 1cm each. However, if we look at the result of the above code
we can clearly see that
a) the nodes seem to be positioned correctly, the appear like there is a 2cm distance between them, as expected;
b) the size of the left two nodes is wrong - I would expect the left two nodes to have the same size as the right two ones, but this isn't the case.
How shall I change my tikzset
code to have the correct sizes of the left two nodes? I don't want to use something like
test/.style =
draw,
circle,
inner sep = 0pt,
semithick,
minimum width = 0.5cm,
,
because I want the node sizes be relative to the node distances and relative to each other. If I would use absolute widths and heights within the style definitions for the nodes, this would be rather unflexible, so I wonder whether it is possible to set the length of "1 unit".
tikz-pgf tikz-styles
tikz-pgf tikz-styles
asked 1 hour ago
T. Pluess
49128
49128
yes I know. But I don't want to use units, as I said - instead I want relative lengths. I.e. the width shall be 1/2 of the node distance and so on.
– T. Pluess
1 hour ago
add a comment |Â
yes I know. But I don't want to use units, as I said - instead I want relative lengths. I.e. the width shall be 1/2 of the node distance and so on.
– T. Pluess
1 hour ago
yes I know. But I don't want to use units, as I said - instead I want relative lengths. I.e. the width shall be 1/2 of the node distance and so on.
– T. Pluess
1 hour ago
yes I know. But I don't want to use units, as I said - instead I want relative lengths. I.e. the width shall be 1/2 of the node distance and so on.
– T. Pluess
1 hour ago
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
4
down vote
You can define a style unit length
that set a custom length unitlen
that you can use later in your drawings. I set the default value to 1cm
in the following code.
documentclass[tikz,border=7pt]standalone
usetikzlibrarypositioning
newlengthunitlen
tikzset
unit length/.code=setlengthunitlen#1,
unit length = 1cm,
node distance = 2,
auto,
on grid,
test/.style =
draw,
circle,
inner sep = 0pt,
semithick,
minimum width = 0.5unitlen,
,
box/.style =
draw,
rectangle,
minimum width = 1unitlen,
minimum height = 1unitlen,
inner sep = 0pt,
,
begindocument
begintikzpicture
node (node1) at (0,0) [label=right:test, test] ;
node (node2) [below=of node1, label=right:box, box] ;
beginscope[unit length=.5cm]
node (node3) [right=of node1, label=right:test, test] ;
node (node4) [below=of node3, label=right:box, box] ;
endscope
endtikzpicture
enddocument
Remarks :
- The
x=1cm
andy=1cm
are used only for coordinates without units, no for lengths. - Another solution is to pass a parameter to your
box
andtest
that is a length set by default to 1cm.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
You can define a style unit length
that set a custom length unitlen
that you can use later in your drawings. I set the default value to 1cm
in the following code.
documentclass[tikz,border=7pt]standalone
usetikzlibrarypositioning
newlengthunitlen
tikzset
unit length/.code=setlengthunitlen#1,
unit length = 1cm,
node distance = 2,
auto,
on grid,
test/.style =
draw,
circle,
inner sep = 0pt,
semithick,
minimum width = 0.5unitlen,
,
box/.style =
draw,
rectangle,
minimum width = 1unitlen,
minimum height = 1unitlen,
inner sep = 0pt,
,
begindocument
begintikzpicture
node (node1) at (0,0) [label=right:test, test] ;
node (node2) [below=of node1, label=right:box, box] ;
beginscope[unit length=.5cm]
node (node3) [right=of node1, label=right:test, test] ;
node (node4) [below=of node3, label=right:box, box] ;
endscope
endtikzpicture
enddocument
Remarks :
- The
x=1cm
andy=1cm
are used only for coordinates without units, no for lengths. - Another solution is to pass a parameter to your
box
andtest
that is a length set by default to 1cm.
add a comment |Â
up vote
4
down vote
You can define a style unit length
that set a custom length unitlen
that you can use later in your drawings. I set the default value to 1cm
in the following code.
documentclass[tikz,border=7pt]standalone
usetikzlibrarypositioning
newlengthunitlen
tikzset
unit length/.code=setlengthunitlen#1,
unit length = 1cm,
node distance = 2,
auto,
on grid,
test/.style =
draw,
circle,
inner sep = 0pt,
semithick,
minimum width = 0.5unitlen,
,
box/.style =
draw,
rectangle,
minimum width = 1unitlen,
minimum height = 1unitlen,
inner sep = 0pt,
,
begindocument
begintikzpicture
node (node1) at (0,0) [label=right:test, test] ;
node (node2) [below=of node1, label=right:box, box] ;
beginscope[unit length=.5cm]
node (node3) [right=of node1, label=right:test, test] ;
node (node4) [below=of node3, label=right:box, box] ;
endscope
endtikzpicture
enddocument
Remarks :
- The
x=1cm
andy=1cm
are used only for coordinates without units, no for lengths. - Another solution is to pass a parameter to your
box
andtest
that is a length set by default to 1cm.
add a comment |Â
up vote
4
down vote
up vote
4
down vote
You can define a style unit length
that set a custom length unitlen
that you can use later in your drawings. I set the default value to 1cm
in the following code.
documentclass[tikz,border=7pt]standalone
usetikzlibrarypositioning
newlengthunitlen
tikzset
unit length/.code=setlengthunitlen#1,
unit length = 1cm,
node distance = 2,
auto,
on grid,
test/.style =
draw,
circle,
inner sep = 0pt,
semithick,
minimum width = 0.5unitlen,
,
box/.style =
draw,
rectangle,
minimum width = 1unitlen,
minimum height = 1unitlen,
inner sep = 0pt,
,
begindocument
begintikzpicture
node (node1) at (0,0) [label=right:test, test] ;
node (node2) [below=of node1, label=right:box, box] ;
beginscope[unit length=.5cm]
node (node3) [right=of node1, label=right:test, test] ;
node (node4) [below=of node3, label=right:box, box] ;
endscope
endtikzpicture
enddocument
Remarks :
- The
x=1cm
andy=1cm
are used only for coordinates without units, no for lengths. - Another solution is to pass a parameter to your
box
andtest
that is a length set by default to 1cm.
You can define a style unit length
that set a custom length unitlen
that you can use later in your drawings. I set the default value to 1cm
in the following code.
documentclass[tikz,border=7pt]standalone
usetikzlibrarypositioning
newlengthunitlen
tikzset
unit length/.code=setlengthunitlen#1,
unit length = 1cm,
node distance = 2,
auto,
on grid,
test/.style =
draw,
circle,
inner sep = 0pt,
semithick,
minimum width = 0.5unitlen,
,
box/.style =
draw,
rectangle,
minimum width = 1unitlen,
minimum height = 1unitlen,
inner sep = 0pt,
,
begindocument
begintikzpicture
node (node1) at (0,0) [label=right:test, test] ;
node (node2) [below=of node1, label=right:box, box] ;
beginscope[unit length=.5cm]
node (node3) [right=of node1, label=right:test, test] ;
node (node4) [below=of node3, label=right:box, box] ;
endscope
endtikzpicture
enddocument
Remarks :
- The
x=1cm
andy=1cm
are used only for coordinates without units, no for lengths. - Another solution is to pass a parameter to your
box
andtest
that is a length set by default to 1cm.
answered 46 mins ago


Kpym
15.2k23781
15.2k23781
add a comment |Â
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%2f454596%2fglobally-configure-length-units-in-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
yes I know. But I don't want to use units, as I said - instead I want relative lengths. I.e. the width shall be 1/2 of the node distance and so on.
– T. Pluess
1 hour ago