Newenvironment - find the length of input











up vote
2
down vote

favorite












I am trying to define a new environment where the input text is placed inside a minipage, which has width equal to the length of the input text (something like a variable width box). What I would like to have additional is a horizontal line over the box which has length more than the input text (say 1.5*input-text-width), as shown below:



enter image description here



Though there are many methods to create a variable width box, I didn't see a way to draw a line over the box which which has its length connected to the input text. I believe that determining the length of the input text is the right way to proceed. In newcommand, the length can be easily determined, since the input text can be called as #1. My question is how to decide the input text length for a newenvironment. More exactly, where is the text-body defined inside the newenviroment?



A minimum working example is:



documentclass{article}

newenvironment{varlength}{
begin{center}
rule{0.9textwidth}{0.8pt}

begin{minipage}{0.6textwidth}}{
end{minipage}
end{center}}


begin{document}
begin{varlength}
This is a text inside fixed length minipage with over-line

I want the same to be repeated for variable width box
end{varlength}
end{document}









share|improve this question
























  • Look for varwidth in the answers to the question marked as duplicate.
    – egreg
    Dec 1 at 16:13












  • @egreg, thanks for the link. But in my environment, there is a line which spans over the text and has a length equal to 1.2 times the input-text-length. That's why I was asking for a way to find input length. I could not find a way to fix it in the link you shared. Should I edit my question?
    – Ashok
    Dec 1 at 18:58












  • Sorry, but I don't understand.
    – egreg
    Dec 1 at 20:40










  • @egred, I have edited my question, sorry for the delayed response.
    – Ashok
    Dec 4 at 14:26















up vote
2
down vote

favorite












I am trying to define a new environment where the input text is placed inside a minipage, which has width equal to the length of the input text (something like a variable width box). What I would like to have additional is a horizontal line over the box which has length more than the input text (say 1.5*input-text-width), as shown below:



enter image description here



Though there are many methods to create a variable width box, I didn't see a way to draw a line over the box which which has its length connected to the input text. I believe that determining the length of the input text is the right way to proceed. In newcommand, the length can be easily determined, since the input text can be called as #1. My question is how to decide the input text length for a newenvironment. More exactly, where is the text-body defined inside the newenviroment?



A minimum working example is:



documentclass{article}

newenvironment{varlength}{
begin{center}
rule{0.9textwidth}{0.8pt}

begin{minipage}{0.6textwidth}}{
end{minipage}
end{center}}


begin{document}
begin{varlength}
This is a text inside fixed length minipage with over-line

I want the same to be repeated for variable width box
end{varlength}
end{document}









share|improve this question
























  • Look for varwidth in the answers to the question marked as duplicate.
    – egreg
    Dec 1 at 16:13












  • @egreg, thanks for the link. But in my environment, there is a line which spans over the text and has a length equal to 1.2 times the input-text-length. That's why I was asking for a way to find input length. I could not find a way to fix it in the link you shared. Should I edit my question?
    – Ashok
    Dec 1 at 18:58












  • Sorry, but I don't understand.
    – egreg
    Dec 1 at 20:40










  • @egred, I have edited my question, sorry for the delayed response.
    – Ashok
    Dec 4 at 14:26













up vote
2
down vote

favorite









up vote
2
down vote

favorite











I am trying to define a new environment where the input text is placed inside a minipage, which has width equal to the length of the input text (something like a variable width box). What I would like to have additional is a horizontal line over the box which has length more than the input text (say 1.5*input-text-width), as shown below:



enter image description here



Though there are many methods to create a variable width box, I didn't see a way to draw a line over the box which which has its length connected to the input text. I believe that determining the length of the input text is the right way to proceed. In newcommand, the length can be easily determined, since the input text can be called as #1. My question is how to decide the input text length for a newenvironment. More exactly, where is the text-body defined inside the newenviroment?



A minimum working example is:



documentclass{article}

newenvironment{varlength}{
begin{center}
rule{0.9textwidth}{0.8pt}

begin{minipage}{0.6textwidth}}{
end{minipage}
end{center}}


begin{document}
begin{varlength}
This is a text inside fixed length minipage with over-line

I want the same to be repeated for variable width box
end{varlength}
end{document}









share|improve this question















I am trying to define a new environment where the input text is placed inside a minipage, which has width equal to the length of the input text (something like a variable width box). What I would like to have additional is a horizontal line over the box which has length more than the input text (say 1.5*input-text-width), as shown below:



enter image description here



Though there are many methods to create a variable width box, I didn't see a way to draw a line over the box which which has its length connected to the input text. I believe that determining the length of the input text is the right way to proceed. In newcommand, the length can be easily determined, since the input text can be called as #1. My question is how to decide the input text length for a newenvironment. More exactly, where is the text-body defined inside the newenviroment?



A minimum working example is:



documentclass{article}

newenvironment{varlength}{
begin{center}
rule{0.9textwidth}{0.8pt}

begin{minipage}{0.6textwidth}}{
end{minipage}
end{center}}


begin{document}
begin{varlength}
This is a text inside fixed length minipage with over-line

I want the same to be repeated for variable width box
end{varlength}
end{document}






environments lengths






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 4 at 14:25

























asked Dec 1 at 16:07









Ashok

367211




367211












  • Look for varwidth in the answers to the question marked as duplicate.
    – egreg
    Dec 1 at 16:13












  • @egreg, thanks for the link. But in my environment, there is a line which spans over the text and has a length equal to 1.2 times the input-text-length. That's why I was asking for a way to find input length. I could not find a way to fix it in the link you shared. Should I edit my question?
    – Ashok
    Dec 1 at 18:58












  • Sorry, but I don't understand.
    – egreg
    Dec 1 at 20:40










  • @egred, I have edited my question, sorry for the delayed response.
    – Ashok
    Dec 4 at 14:26


















  • Look for varwidth in the answers to the question marked as duplicate.
    – egreg
    Dec 1 at 16:13












  • @egreg, thanks for the link. But in my environment, there is a line which spans over the text and has a length equal to 1.2 times the input-text-length. That's why I was asking for a way to find input length. I could not find a way to fix it in the link you shared. Should I edit my question?
    – Ashok
    Dec 1 at 18:58












  • Sorry, but I don't understand.
    – egreg
    Dec 1 at 20:40










  • @egred, I have edited my question, sorry for the delayed response.
    – Ashok
    Dec 4 at 14:26
















Look for varwidth in the answers to the question marked as duplicate.
– egreg
Dec 1 at 16:13






Look for varwidth in the answers to the question marked as duplicate.
– egreg
Dec 1 at 16:13














@egreg, thanks for the link. But in my environment, there is a line which spans over the text and has a length equal to 1.2 times the input-text-length. That's why I was asking for a way to find input length. I could not find a way to fix it in the link you shared. Should I edit my question?
– Ashok
Dec 1 at 18:58






@egreg, thanks for the link. But in my environment, there is a line which spans over the text and has a length equal to 1.2 times the input-text-length. That's why I was asking for a way to find input length. I could not find a way to fix it in the link you shared. Should I edit my question?
– Ashok
Dec 1 at 18:58














Sorry, but I don't understand.
– egreg
Dec 1 at 20:40




Sorry, but I don't understand.
– egreg
Dec 1 at 20:40












@egred, I have edited my question, sorry for the delayed response.
– Ashok
Dec 4 at 14:26




@egred, I have edited my question, sorry for the delayed response.
– Ashok
Dec 4 at 14:26










1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










The “length of the input” doesn't make much sense, because TeX typesets paragraphs at a fixed size, using the current value of the parameter hsize (normally equal to textwidth in LaTeX).



You can have minipages that adapt to the size of the material inside them using varwidth:



documentclass{article}
usepackage{varwidth}

newsavebox{varlengthbox}
newenvironment{varlength}
{begin{lrbox}{varlengthbox}begin{varwidth}{textwidth}}
{end{varwidth}end{lrbox}
begin{center}
rule{1.5wdvarlengthbox}{0.4pt}\
usebox{varlengthbox}
end{center}}

begin{document}

begin{varlength}
This is a text inside fixed length\
minipage with over-line

I want the same to be repeated for\
variable width box
end{varlength}

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',
    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%2f462709%2fnewenvironment-find-the-length-of-input%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








    up vote
    2
    down vote



    accepted










    The “length of the input” doesn't make much sense, because TeX typesets paragraphs at a fixed size, using the current value of the parameter hsize (normally equal to textwidth in LaTeX).



    You can have minipages that adapt to the size of the material inside them using varwidth:



    documentclass{article}
    usepackage{varwidth}

    newsavebox{varlengthbox}
    newenvironment{varlength}
    {begin{lrbox}{varlengthbox}begin{varwidth}{textwidth}}
    {end{varwidth}end{lrbox}
    begin{center}
    rule{1.5wdvarlengthbox}{0.4pt}\
    usebox{varlengthbox}
    end{center}}

    begin{document}

    begin{varlength}
    This is a text inside fixed length\
    minipage with over-line

    I want the same to be repeated for\
    variable width box
    end{varlength}

    end{document}


    enter image description here






    share|improve this answer

























      up vote
      2
      down vote



      accepted










      The “length of the input” doesn't make much sense, because TeX typesets paragraphs at a fixed size, using the current value of the parameter hsize (normally equal to textwidth in LaTeX).



      You can have minipages that adapt to the size of the material inside them using varwidth:



      documentclass{article}
      usepackage{varwidth}

      newsavebox{varlengthbox}
      newenvironment{varlength}
      {begin{lrbox}{varlengthbox}begin{varwidth}{textwidth}}
      {end{varwidth}end{lrbox}
      begin{center}
      rule{1.5wdvarlengthbox}{0.4pt}\
      usebox{varlengthbox}
      end{center}}

      begin{document}

      begin{varlength}
      This is a text inside fixed length\
      minipage with over-line

      I want the same to be repeated for\
      variable width box
      end{varlength}

      end{document}


      enter image description here






      share|improve this answer























        up vote
        2
        down vote



        accepted







        up vote
        2
        down vote



        accepted






        The “length of the input” doesn't make much sense, because TeX typesets paragraphs at a fixed size, using the current value of the parameter hsize (normally equal to textwidth in LaTeX).



        You can have minipages that adapt to the size of the material inside them using varwidth:



        documentclass{article}
        usepackage{varwidth}

        newsavebox{varlengthbox}
        newenvironment{varlength}
        {begin{lrbox}{varlengthbox}begin{varwidth}{textwidth}}
        {end{varwidth}end{lrbox}
        begin{center}
        rule{1.5wdvarlengthbox}{0.4pt}\
        usebox{varlengthbox}
        end{center}}

        begin{document}

        begin{varlength}
        This is a text inside fixed length\
        minipage with over-line

        I want the same to be repeated for\
        variable width box
        end{varlength}

        end{document}


        enter image description here






        share|improve this answer












        The “length of the input” doesn't make much sense, because TeX typesets paragraphs at a fixed size, using the current value of the parameter hsize (normally equal to textwidth in LaTeX).



        You can have minipages that adapt to the size of the material inside them using varwidth:



        documentclass{article}
        usepackage{varwidth}

        newsavebox{varlengthbox}
        newenvironment{varlength}
        {begin{lrbox}{varlengthbox}begin{varwidth}{textwidth}}
        {end{varwidth}end{lrbox}
        begin{center}
        rule{1.5wdvarlengthbox}{0.4pt}\
        usebox{varlengthbox}
        end{center}}

        begin{document}

        begin{varlength}
        This is a text inside fixed length\
        minipage with over-line

        I want the same to be repeated for\
        variable width box
        end{varlength}

        end{document}


        enter image description here







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 4 at 14:54









        egreg

        703k8618733148




        703k8618733148






























            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2f462709%2fnewenvironment-find-the-length-of-input%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

            Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

            ComboBox Display Member on multiple fields

            Is it possible to collect Nectar points via Trainline?