Globally configure length units in TikZ

The name of the pictureThe name of the pictureThe name of the pictureClash 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



wrong distances



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".










share|improve this question





















  • 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














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



wrong distances



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".










share|improve this question





















  • 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












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



wrong distances



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".










share|improve this question













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



wrong distances



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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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
















  • 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










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


enter image description here



Remarks :



  • The x=1cm and y=1cm are used only for coordinates without units, no for lengths.

  • Another solution is to pass a parameter to your box and test that is a length set by default to 1cm.





share|improve this answer




















    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',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    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






























    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


    enter image description here



    Remarks :



    • The x=1cm and y=1cm are used only for coordinates without units, no for lengths.

    • Another solution is to pass a parameter to your box and test that is a length set by default to 1cm.





    share|improve this answer
























      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


      enter image description here



      Remarks :



      • The x=1cm and y=1cm are used only for coordinates without units, no for lengths.

      • Another solution is to pass a parameter to your box and test that is a length set by default to 1cm.





      share|improve this answer






















        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


        enter image description here



        Remarks :



        • The x=1cm and y=1cm are used only for coordinates without units, no for lengths.

        • Another solution is to pass a parameter to your box and test that is a length set by default to 1cm.





        share|improve this answer












        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


        enter image description here



        Remarks :



        • The x=1cm and y=1cm are used only for coordinates without units, no for lengths.

        • Another solution is to pass a parameter to your box and test that is a length set by default to 1cm.






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 46 mins ago









        Kpym

        15.2k23781




        15.2k23781



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            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













































































            Comments

            Popular posts from this blog

            What does second last employer means? [closed]

            List of Gilmore Girls characters

            Confectionery