How to make labels automatically scale in size to fit between 2 coordinates in tikz?How to make (1,1) mean...

Have I found a major security issue with login

Would it be possible to set up a franchise in the ancient world?

What were the "pills" that were added to solid waste in Apollo 7?

Is it a good idea to teach algorithm courses using pseudocode instead of a real programming language?

Greek theta instead of lower case þ (Icelandic) in TexStudio

What's is the easiest way to purchase a stock and hold it

Why didn't Daenerys' advisers suggest assassinating Cersei?

Very serious stuff - Salesforce bug enabled "Modify All"

How to fix "webpack Dev Server Invalid Options" in Vuejs

pwaS eht tirsf dna tasl setterl fo hace dorw

Is a reptile with diamond scales possible?

Find the 3D region containing the origin bounded by given planes

Can't think of a good word or term to describe not feeling or thinking

Warped chessboard

Bash Read: Reading comma separated list, last element is missed

Have the writers and actors of Game Of Thrones responded to its poor reception?

Why did Nick Fury not hesitate in blowing up the plane he thought was carrying a nuke?

How does the "reverse syntax" in Middle English work?

Can 2 light bulbs of 120V in series be used on 230V AC?

How to make labels automatically scale in size to fit between 2 coordinates in tikz?

How come Arya Stark wasn't hurt by this in Game of Thrones Season 8 Episode 5?

On a piano, are the effects of holding notes and the sustain pedal the same for a single chord?

Richard's Favourite TV Programme

How to plot a surface from a system of equations?



How to make labels automatically scale in size to fit between 2 coordinates in tikz?


How to make (1,1) mean (1cm,1cm) in TikZ? (Setting the units of coordinates)How do I achieve consistent font sizing in a tikz circuit?how to set the canvas and font size in TikZ?Scaling TikZ figures for posterScale TikZ nodes and shapes for a given canvas sizePreserve node and font size when scalingTikZ scaling graphic and adjust node position and keep font sizeTikZ “scale” key not behaving at all in the expected way when scaling tikzpictureLine up nested tikz enviroments or how to get rid of themHow do I change the size of a state in a FSA in tikz?













3















tikz newbie here.



I want to make "template" drawing, which has part of it a line and then put different size labels on top of the line.



The label is some latex code (equation).



One of the problems is that, since I am using fixed coordinates each time, but the equation itself can be long or short, I need a way to make the latex font size automatically scale to fit the space.



Otherwise, each time I make new drawing, I have to do trial and error to change either the coordinates or manually change the font size. Here is MWE to better explain what I mean



documentclass[11pt]{standalone}
usepackage{tikz}

begin{document}
begin{tikzpicture}


coordinate[label=left:A] (A) at (0,0);
coordinate[label=right:B] (B) at (3,0);

newcommand{myLabel}{$sin(x)+cos(y)=int_0^infty e^{x y}, dx$}

draw (A) -- node[above] {myLabel} ++(B);

end{tikzpicture}
end{document}


Mathematica graphics



Now, I can either try again with smaller font or change the coordinates to make the space larger so the new label fit.



I do not want to change the coordinates, since if these are part of larger diagram, it means I have to also change other coordinates as well and things will start to fall apart, because once I change one coordinate, I have to go update all the other coordinates to keep the shape the same.



So I try again with smaller font, like this



newcommand{myLabel}{{footnotesize{$sin(x)+cos(y)=int_0^infty e^{x y}, dx$}}};


Ok, a little better



Mathematica graphics



but still does not fit right. So I try now with



 newcommand{myLabel}{{tiny{$sin(x)+cos(y)=int_0^infty e^{x y}, dx$}}};


Mathematica graphics



Ok a little better.



But this is all trial and error. I want a way to automate this by telling tikz to scale the text between 2 coordinates on a line to "fit".



What would be a good way to do this sort of thing? i.e I want labels to automatically "fit" in the space they are in without having to edit coordinates each time I change the label.










share|improve this question



























    3















    tikz newbie here.



    I want to make "template" drawing, which has part of it a line and then put different size labels on top of the line.



    The label is some latex code (equation).



    One of the problems is that, since I am using fixed coordinates each time, but the equation itself can be long or short, I need a way to make the latex font size automatically scale to fit the space.



    Otherwise, each time I make new drawing, I have to do trial and error to change either the coordinates or manually change the font size. Here is MWE to better explain what I mean



    documentclass[11pt]{standalone}
    usepackage{tikz}

    begin{document}
    begin{tikzpicture}


    coordinate[label=left:A] (A) at (0,0);
    coordinate[label=right:B] (B) at (3,0);

    newcommand{myLabel}{$sin(x)+cos(y)=int_0^infty e^{x y}, dx$}

    draw (A) -- node[above] {myLabel} ++(B);

    end{tikzpicture}
    end{document}


    Mathematica graphics



    Now, I can either try again with smaller font or change the coordinates to make the space larger so the new label fit.



    I do not want to change the coordinates, since if these are part of larger diagram, it means I have to also change other coordinates as well and things will start to fall apart, because once I change one coordinate, I have to go update all the other coordinates to keep the shape the same.



    So I try again with smaller font, like this



    newcommand{myLabel}{{footnotesize{$sin(x)+cos(y)=int_0^infty e^{x y}, dx$}}};


    Ok, a little better



    Mathematica graphics



    but still does not fit right. So I try now with



     newcommand{myLabel}{{tiny{$sin(x)+cos(y)=int_0^infty e^{x y}, dx$}}};


    Mathematica graphics



    Ok a little better.



    But this is all trial and error. I want a way to automate this by telling tikz to scale the text between 2 coordinates on a line to "fit".



    What would be a good way to do this sort of thing? i.e I want labels to automatically "fit" in the space they are in without having to edit coordinates each time I change the label.










    share|improve this question

























      3












      3








      3


      1






      tikz newbie here.



      I want to make "template" drawing, which has part of it a line and then put different size labels on top of the line.



      The label is some latex code (equation).



      One of the problems is that, since I am using fixed coordinates each time, but the equation itself can be long or short, I need a way to make the latex font size automatically scale to fit the space.



      Otherwise, each time I make new drawing, I have to do trial and error to change either the coordinates or manually change the font size. Here is MWE to better explain what I mean



      documentclass[11pt]{standalone}
      usepackage{tikz}

      begin{document}
      begin{tikzpicture}


      coordinate[label=left:A] (A) at (0,0);
      coordinate[label=right:B] (B) at (3,0);

      newcommand{myLabel}{$sin(x)+cos(y)=int_0^infty e^{x y}, dx$}

      draw (A) -- node[above] {myLabel} ++(B);

      end{tikzpicture}
      end{document}


      Mathematica graphics



      Now, I can either try again with smaller font or change the coordinates to make the space larger so the new label fit.



      I do not want to change the coordinates, since if these are part of larger diagram, it means I have to also change other coordinates as well and things will start to fall apart, because once I change one coordinate, I have to go update all the other coordinates to keep the shape the same.



      So I try again with smaller font, like this



      newcommand{myLabel}{{footnotesize{$sin(x)+cos(y)=int_0^infty e^{x y}, dx$}}};


      Ok, a little better



      Mathematica graphics



      but still does not fit right. So I try now with



       newcommand{myLabel}{{tiny{$sin(x)+cos(y)=int_0^infty e^{x y}, dx$}}};


      Mathematica graphics



      Ok a little better.



      But this is all trial and error. I want a way to automate this by telling tikz to scale the text between 2 coordinates on a line to "fit".



      What would be a good way to do this sort of thing? i.e I want labels to automatically "fit" in the space they are in without having to edit coordinates each time I change the label.










      share|improve this question














      tikz newbie here.



      I want to make "template" drawing, which has part of it a line and then put different size labels on top of the line.



      The label is some latex code (equation).



      One of the problems is that, since I am using fixed coordinates each time, but the equation itself can be long or short, I need a way to make the latex font size automatically scale to fit the space.



      Otherwise, each time I make new drawing, I have to do trial and error to change either the coordinates or manually change the font size. Here is MWE to better explain what I mean



      documentclass[11pt]{standalone}
      usepackage{tikz}

      begin{document}
      begin{tikzpicture}


      coordinate[label=left:A] (A) at (0,0);
      coordinate[label=right:B] (B) at (3,0);

      newcommand{myLabel}{$sin(x)+cos(y)=int_0^infty e^{x y}, dx$}

      draw (A) -- node[above] {myLabel} ++(B);

      end{tikzpicture}
      end{document}


      Mathematica graphics



      Now, I can either try again with smaller font or change the coordinates to make the space larger so the new label fit.



      I do not want to change the coordinates, since if these are part of larger diagram, it means I have to also change other coordinates as well and things will start to fall apart, because once I change one coordinate, I have to go update all the other coordinates to keep the shape the same.



      So I try again with smaller font, like this



      newcommand{myLabel}{{footnotesize{$sin(x)+cos(y)=int_0^infty e^{x y}, dx$}}};


      Ok, a little better



      Mathematica graphics



      but still does not fit right. So I try now with



       newcommand{myLabel}{{tiny{$sin(x)+cos(y)=int_0^infty e^{x y}, dx$}}};


      Mathematica graphics



      Ok a little better.



      But this is all trial and error. I want a way to automate this by telling tikz to scale the text between 2 coordinates on a line to "fit".



      What would be a good way to do this sort of thing? i.e I want labels to automatically "fit" in the space they are in without having to edit coordinates each time I change the label.







      tikz-pgf






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 4 hours ago









      NasserNasser

      8,47383490




      8,47383490






















          1 Answer
          1






          active

          oldest

          votes


















          4














          The general strategy is to measure the length of the path and then either measure the width of the node contents (first example) to compute the relevant scale factor, or to use adjustbox to scale the node to the length of the path (second example).



          documentclass[11pt]{standalone}
          usepackage{tikz}
          usetikzlibrary{calc}
          begin{document}
          begin{tikzpicture}


          coordinate[label=left:A] (A) at (0,0);
          coordinate[label=right:B] (B) at (3,0);

          newcommand{myLabel}{$sin(x)+cos(y)=int_0^infty e^{x y}, dx$}
          pgfmathsetmacro{mywidth}{width("myLabel")}
          draw let p1=($(B)-(A)$),n1={veclen(x1,y1)} in (A) --
          node[above,scale={n1/mywidth}] {myLabel} ++(B);

          end{tikzpicture}
          end{document}


          enter image description here



          You can turn this into a style. This case can be adjusted to the actual use cases, which I do not know.



          documentclass[tikz,border=3.14mm]{standalone}
          usetikzlibrary{calc}
          usepackage{adjustbox}
          begin{document}
          begin{tikzpicture}[fitting label/.style args={between #1 and #2 with #3}{%
          insert path={let p1=($(#2)-(#1)$),n1={veclen(x1,y1)}
          in (#1) -- (#2) node[midway]{adjustbox{width=n1}{#3}}
          }}]


          coordinate[label=left:A] (A) at (0,0);
          coordinate[label=right:B] (B) at (3,0);

          newcommand{myLabel}{$displaystylesin(x)+cos(y)=intlimits_0^infty mathrm{e}^{x y},
          mathrm{d}x$}
          draw[above,fitting label=between A and B with myLabel];
          end{tikzpicture}
          end{document}


          enter image description here






          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',
            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
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f491382%2fhow-to-make-labels-automatically-scale-in-size-to-fit-between-2-coordinates-in-t%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            4














            The general strategy is to measure the length of the path and then either measure the width of the node contents (first example) to compute the relevant scale factor, or to use adjustbox to scale the node to the length of the path (second example).



            documentclass[11pt]{standalone}
            usepackage{tikz}
            usetikzlibrary{calc}
            begin{document}
            begin{tikzpicture}


            coordinate[label=left:A] (A) at (0,0);
            coordinate[label=right:B] (B) at (3,0);

            newcommand{myLabel}{$sin(x)+cos(y)=int_0^infty e^{x y}, dx$}
            pgfmathsetmacro{mywidth}{width("myLabel")}
            draw let p1=($(B)-(A)$),n1={veclen(x1,y1)} in (A) --
            node[above,scale={n1/mywidth}] {myLabel} ++(B);

            end{tikzpicture}
            end{document}


            enter image description here



            You can turn this into a style. This case can be adjusted to the actual use cases, which I do not know.



            documentclass[tikz,border=3.14mm]{standalone}
            usetikzlibrary{calc}
            usepackage{adjustbox}
            begin{document}
            begin{tikzpicture}[fitting label/.style args={between #1 and #2 with #3}{%
            insert path={let p1=($(#2)-(#1)$),n1={veclen(x1,y1)}
            in (#1) -- (#2) node[midway]{adjustbox{width=n1}{#3}}
            }}]


            coordinate[label=left:A] (A) at (0,0);
            coordinate[label=right:B] (B) at (3,0);

            newcommand{myLabel}{$displaystylesin(x)+cos(y)=intlimits_0^infty mathrm{e}^{x y},
            mathrm{d}x$}
            draw[above,fitting label=between A and B with myLabel];
            end{tikzpicture}
            end{document}


            enter image description here






            share|improve this answer






























              4














              The general strategy is to measure the length of the path and then either measure the width of the node contents (first example) to compute the relevant scale factor, or to use adjustbox to scale the node to the length of the path (second example).



              documentclass[11pt]{standalone}
              usepackage{tikz}
              usetikzlibrary{calc}
              begin{document}
              begin{tikzpicture}


              coordinate[label=left:A] (A) at (0,0);
              coordinate[label=right:B] (B) at (3,0);

              newcommand{myLabel}{$sin(x)+cos(y)=int_0^infty e^{x y}, dx$}
              pgfmathsetmacro{mywidth}{width("myLabel")}
              draw let p1=($(B)-(A)$),n1={veclen(x1,y1)} in (A) --
              node[above,scale={n1/mywidth}] {myLabel} ++(B);

              end{tikzpicture}
              end{document}


              enter image description here



              You can turn this into a style. This case can be adjusted to the actual use cases, which I do not know.



              documentclass[tikz,border=3.14mm]{standalone}
              usetikzlibrary{calc}
              usepackage{adjustbox}
              begin{document}
              begin{tikzpicture}[fitting label/.style args={between #1 and #2 with #3}{%
              insert path={let p1=($(#2)-(#1)$),n1={veclen(x1,y1)}
              in (#1) -- (#2) node[midway]{adjustbox{width=n1}{#3}}
              }}]


              coordinate[label=left:A] (A) at (0,0);
              coordinate[label=right:B] (B) at (3,0);

              newcommand{myLabel}{$displaystylesin(x)+cos(y)=intlimits_0^infty mathrm{e}^{x y},
              mathrm{d}x$}
              draw[above,fitting label=between A and B with myLabel];
              end{tikzpicture}
              end{document}


              enter image description here






              share|improve this answer




























                4












                4








                4







                The general strategy is to measure the length of the path and then either measure the width of the node contents (first example) to compute the relevant scale factor, or to use adjustbox to scale the node to the length of the path (second example).



                documentclass[11pt]{standalone}
                usepackage{tikz}
                usetikzlibrary{calc}
                begin{document}
                begin{tikzpicture}


                coordinate[label=left:A] (A) at (0,0);
                coordinate[label=right:B] (B) at (3,0);

                newcommand{myLabel}{$sin(x)+cos(y)=int_0^infty e^{x y}, dx$}
                pgfmathsetmacro{mywidth}{width("myLabel")}
                draw let p1=($(B)-(A)$),n1={veclen(x1,y1)} in (A) --
                node[above,scale={n1/mywidth}] {myLabel} ++(B);

                end{tikzpicture}
                end{document}


                enter image description here



                You can turn this into a style. This case can be adjusted to the actual use cases, which I do not know.



                documentclass[tikz,border=3.14mm]{standalone}
                usetikzlibrary{calc}
                usepackage{adjustbox}
                begin{document}
                begin{tikzpicture}[fitting label/.style args={between #1 and #2 with #3}{%
                insert path={let p1=($(#2)-(#1)$),n1={veclen(x1,y1)}
                in (#1) -- (#2) node[midway]{adjustbox{width=n1}{#3}}
                }}]


                coordinate[label=left:A] (A) at (0,0);
                coordinate[label=right:B] (B) at (3,0);

                newcommand{myLabel}{$displaystylesin(x)+cos(y)=intlimits_0^infty mathrm{e}^{x y},
                mathrm{d}x$}
                draw[above,fitting label=between A and B with myLabel];
                end{tikzpicture}
                end{document}


                enter image description here






                share|improve this answer















                The general strategy is to measure the length of the path and then either measure the width of the node contents (first example) to compute the relevant scale factor, or to use adjustbox to scale the node to the length of the path (second example).



                documentclass[11pt]{standalone}
                usepackage{tikz}
                usetikzlibrary{calc}
                begin{document}
                begin{tikzpicture}


                coordinate[label=left:A] (A) at (0,0);
                coordinate[label=right:B] (B) at (3,0);

                newcommand{myLabel}{$sin(x)+cos(y)=int_0^infty e^{x y}, dx$}
                pgfmathsetmacro{mywidth}{width("myLabel")}
                draw let p1=($(B)-(A)$),n1={veclen(x1,y1)} in (A) --
                node[above,scale={n1/mywidth}] {myLabel} ++(B);

                end{tikzpicture}
                end{document}


                enter image description here



                You can turn this into a style. This case can be adjusted to the actual use cases, which I do not know.



                documentclass[tikz,border=3.14mm]{standalone}
                usetikzlibrary{calc}
                usepackage{adjustbox}
                begin{document}
                begin{tikzpicture}[fitting label/.style args={between #1 and #2 with #3}{%
                insert path={let p1=($(#2)-(#1)$),n1={veclen(x1,y1)}
                in (#1) -- (#2) node[midway]{adjustbox{width=n1}{#3}}
                }}]


                coordinate[label=left:A] (A) at (0,0);
                coordinate[label=right:B] (B) at (3,0);

                newcommand{myLabel}{$displaystylesin(x)+cos(y)=intlimits_0^infty mathrm{e}^{x y},
                mathrm{d}x$}
                draw[above,fitting label=between A and B with myLabel];
                end{tikzpicture}
                end{document}


                enter image description here







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 3 hours ago

























                answered 4 hours ago









                marmotmarmot

                128k6162308




                128k6162308






























                    draft saved

                    draft discarded




















































                    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.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f491382%2fhow-to-make-labels-automatically-scale-in-size-to-fit-between-2-coordinates-in-t%23new-answer', 'question_page');
                    }
                    );

                    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







                    Popular posts from this blog

                    Hudson River Historic District Contents Geography History The district today Aesthetics Cultural...

                    The number designs the writing. Feandra Aversely Definition: The act of ingrafting a sprig or shoot of one...

                    Ayherre Geografie Demografie Externe links Navigatiemenu43° 23′ NB, 1° 15′ WL43° 23′ NB, 1°...