Align last word of a paragraph to the right?










4















Is it possible to reliably right-align the last word of a paragraph?



Using hfill works most of the time, looking like



Left stuff Right stuff.


but fails if the rest after hfill doesn't fit into the line. In that case the result looks like



Left stuff. Bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla
Right stuff.


but I want to get



Left stuff. Bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla
Right stuff.


Actual example document



enter image description here



documentclass[12pt]article

begindocument

noindenttextbfIn real document, I would use textttstringhfill instead of textttstringhrulefill. The latter just demonstrates it better in an example document.

.

noindenttextbfThe command textttstringhfill is useful for aligning short text to left and right easily.

noindent Bla bla.
hrulefill Yada yada.

.

noindenttextbfIf the parts get too long, they are not correctly aligned.

noindent Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla.
hrulefill Yada Yada Yada Yada Yada Yada Yada Yada Yada.

.

noindenttextbfBoxes don't help.

noindent hboxBla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla.
hrulefill hboxYada Yada Yada Yada Yada Yada Yada Yada Yada.

.

noindenttextbfWhat I am actually trying to do.

noindent Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla
hrulefill (statement:1)

.

noindent Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla Bla Bla
hrulefill (statement:1)

.

noindenttextbfAn approximation of what it should look like, if the last line before ``(statement:1)'' is full.

noindent Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla Bla Bla
\.hrulefill (statement:1)


enddocument









share|improve this question


























    4















    Is it possible to reliably right-align the last word of a paragraph?



    Using hfill works most of the time, looking like



    Left stuff Right stuff.


    but fails if the rest after hfill doesn't fit into the line. In that case the result looks like



    Left stuff. Bla bla bla bla bla bla bla bla bla bla
    bla bla bla bla bla bla bla bla bla bla bla
    Right stuff.


    but I want to get



    Left stuff. Bla bla bla bla bla bla bla bla bla bla
    bla bla bla bla bla bla bla bla bla bla bla
    Right stuff.


    Actual example document



    enter image description here



    documentclass[12pt]article

    begindocument

    noindenttextbfIn real document, I would use textttstringhfill instead of textttstringhrulefill. The latter just demonstrates it better in an example document.

    .

    noindenttextbfThe command textttstringhfill is useful for aligning short text to left and right easily.

    noindent Bla bla.
    hrulefill Yada yada.

    .

    noindenttextbfIf the parts get too long, they are not correctly aligned.

    noindent Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla.
    hrulefill Yada Yada Yada Yada Yada Yada Yada Yada Yada.

    .

    noindenttextbfBoxes don't help.

    noindent hboxBla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla.
    hrulefill hboxYada Yada Yada Yada Yada Yada Yada Yada Yada.

    .

    noindenttextbfWhat I am actually trying to do.

    noindent Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla
    hrulefill (statement:1)

    .

    noindent Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla Bla Bla
    hrulefill (statement:1)

    .

    noindenttextbfAn approximation of what it should look like, if the last line before ``(statement:1)'' is full.

    noindent Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla Bla Bla
    \.hrulefill (statement:1)


    enddocument









    share|improve this question
























      4












      4








      4








      Is it possible to reliably right-align the last word of a paragraph?



      Using hfill works most of the time, looking like



      Left stuff Right stuff.


      but fails if the rest after hfill doesn't fit into the line. In that case the result looks like



      Left stuff. Bla bla bla bla bla bla bla bla bla bla
      bla bla bla bla bla bla bla bla bla bla bla
      Right stuff.


      but I want to get



      Left stuff. Bla bla bla bla bla bla bla bla bla bla
      bla bla bla bla bla bla bla bla bla bla bla
      Right stuff.


      Actual example document



      enter image description here



      documentclass[12pt]article

      begindocument

      noindenttextbfIn real document, I would use textttstringhfill instead of textttstringhrulefill. The latter just demonstrates it better in an example document.

      .

      noindenttextbfThe command textttstringhfill is useful for aligning short text to left and right easily.

      noindent Bla bla.
      hrulefill Yada yada.

      .

      noindenttextbfIf the parts get too long, they are not correctly aligned.

      noindent Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla.
      hrulefill Yada Yada Yada Yada Yada Yada Yada Yada Yada.

      .

      noindenttextbfBoxes don't help.

      noindent hboxBla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla.
      hrulefill hboxYada Yada Yada Yada Yada Yada Yada Yada Yada.

      .

      noindenttextbfWhat I am actually trying to do.

      noindent Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla
      hrulefill (statement:1)

      .

      noindent Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla Bla Bla
      hrulefill (statement:1)

      .

      noindenttextbfAn approximation of what it should look like, if the last line before ``(statement:1)'' is full.

      noindent Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla Bla Bla
      \.hrulefill (statement:1)


      enddocument









      share|improve this question














      Is it possible to reliably right-align the last word of a paragraph?



      Using hfill works most of the time, looking like



      Left stuff Right stuff.


      but fails if the rest after hfill doesn't fit into the line. In that case the result looks like



      Left stuff. Bla bla bla bla bla bla bla bla bla bla
      bla bla bla bla bla bla bla bla bla bla bla
      Right stuff.


      but I want to get



      Left stuff. Bla bla bla bla bla bla bla bla bla bla
      bla bla bla bla bla bla bla bla bla bla bla
      Right stuff.


      Actual example document



      enter image description here



      documentclass[12pt]article

      begindocument

      noindenttextbfIn real document, I would use textttstringhfill instead of textttstringhrulefill. The latter just demonstrates it better in an example document.

      .

      noindenttextbfThe command textttstringhfill is useful for aligning short text to left and right easily.

      noindent Bla bla.
      hrulefill Yada yada.

      .

      noindenttextbfIf the parts get too long, they are not correctly aligned.

      noindent Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla.
      hrulefill Yada Yada Yada Yada Yada Yada Yada Yada Yada.

      .

      noindenttextbfBoxes don't help.

      noindent hboxBla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla.
      hrulefill hboxYada Yada Yada Yada Yada Yada Yada Yada Yada.

      .

      noindenttextbfWhat I am actually trying to do.

      noindent Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla
      hrulefill (statement:1)

      .

      noindent Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla Bla Bla
      hrulefill (statement:1)

      .

      noindenttextbfAn approximation of what it should look like, if the last line before ``(statement:1)'' is full.

      noindent Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla Bla Bla
      \.hrulefill (statement:1)


      enddocument






      horizontal-alignment






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 12 '18 at 11:01









      kdbkdb

      832514




      832514




















          1 Answer
          1






          active

          oldest

          votes


















          6














          There is a nice example in The TeXbook to do this. See chapter 14, page 106.



          documentclassarticle
          defsigned #1 (#2)unskipnobreakhfilpenalty50
          hskip2emhboxnobreakhfilsl#1/ rm(#2)
          parfillskip=0pt finalhyphendemerits=0 par
          begindocument
          hsize 9cm
          This is a case where the name and address fit in nicely with the review.
          signed A. Reviewer (Ann Arbor, Mich.)

          But sometimes an extra line must be added. signed N. Bourbaki (Paris)
          enddocument


          output



          You could make it a bit more standard for LaTeX:



          documentclassarticle
          newcommandsigned[1]%
          unskipnobreakhfilpenalty50
          hskip2emhboxnobreakhfil#1
          parfillskip=0pt finalhyphendemerits=0 par
          begindocument
          hsize 9cm
          This is a case where the name and address fit in nicely with the review.
          signedemphA. Reviewer (Ann Arbor, Mich.)

          But sometimes an extra line must be added. signedemphN. Bourbaki (Paris)
          enddocument


          And the explanation of how it works from The TeXbook:




          If a line break occurs at the penalty50, the hskip2em will disappear
          and the empty hbox will occur at the beginning of a line, followed by
          hfil glue. This yields two lines whose badness is zero; the first of
          these lines is assessed a penalty of 50. But if no line break occurs
          at the penalty50, there will be glue of 2 em plus 2 fil between the
          review and the name; this yields one line of badness zero. TEX will
          try both alternatives, to see which leads to the fewest total
          demerits. The one-line solution will usually be preferred if it is
          feasible.







          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%2f459594%2falign-last-word-of-a-paragraph-to-the-right%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









            6














            There is a nice example in The TeXbook to do this. See chapter 14, page 106.



            documentclassarticle
            defsigned #1 (#2)unskipnobreakhfilpenalty50
            hskip2emhboxnobreakhfilsl#1/ rm(#2)
            parfillskip=0pt finalhyphendemerits=0 par
            begindocument
            hsize 9cm
            This is a case where the name and address fit in nicely with the review.
            signed A. Reviewer (Ann Arbor, Mich.)

            But sometimes an extra line must be added. signed N. Bourbaki (Paris)
            enddocument


            output



            You could make it a bit more standard for LaTeX:



            documentclassarticle
            newcommandsigned[1]%
            unskipnobreakhfilpenalty50
            hskip2emhboxnobreakhfil#1
            parfillskip=0pt finalhyphendemerits=0 par
            begindocument
            hsize 9cm
            This is a case where the name and address fit in nicely with the review.
            signedemphA. Reviewer (Ann Arbor, Mich.)

            But sometimes an extra line must be added. signedemphN. Bourbaki (Paris)
            enddocument


            And the explanation of how it works from The TeXbook:




            If a line break occurs at the penalty50, the hskip2em will disappear
            and the empty hbox will occur at the beginning of a line, followed by
            hfil glue. This yields two lines whose badness is zero; the first of
            these lines is assessed a penalty of 50. But if no line break occurs
            at the penalty50, there will be glue of 2 em plus 2 fil between the
            review and the name; this yields one line of badness zero. TEX will
            try both alternatives, to see which leads to the fewest total
            demerits. The one-line solution will usually be preferred if it is
            feasible.







            share|improve this answer





























              6














              There is a nice example in The TeXbook to do this. See chapter 14, page 106.



              documentclassarticle
              defsigned #1 (#2)unskipnobreakhfilpenalty50
              hskip2emhboxnobreakhfilsl#1/ rm(#2)
              parfillskip=0pt finalhyphendemerits=0 par
              begindocument
              hsize 9cm
              This is a case where the name and address fit in nicely with the review.
              signed A. Reviewer (Ann Arbor, Mich.)

              But sometimes an extra line must be added. signed N. Bourbaki (Paris)
              enddocument


              output



              You could make it a bit more standard for LaTeX:



              documentclassarticle
              newcommandsigned[1]%
              unskipnobreakhfilpenalty50
              hskip2emhboxnobreakhfil#1
              parfillskip=0pt finalhyphendemerits=0 par
              begindocument
              hsize 9cm
              This is a case where the name and address fit in nicely with the review.
              signedemphA. Reviewer (Ann Arbor, Mich.)

              But sometimes an extra line must be added. signedemphN. Bourbaki (Paris)
              enddocument


              And the explanation of how it works from The TeXbook:




              If a line break occurs at the penalty50, the hskip2em will disappear
              and the empty hbox will occur at the beginning of a line, followed by
              hfil glue. This yields two lines whose badness is zero; the first of
              these lines is assessed a penalty of 50. But if no line break occurs
              at the penalty50, there will be glue of 2 em plus 2 fil between the
              review and the name; this yields one line of badness zero. TEX will
              try both alternatives, to see which leads to the fewest total
              demerits. The one-line solution will usually be preferred if it is
              feasible.







              share|improve this answer



























                6












                6








                6







                There is a nice example in The TeXbook to do this. See chapter 14, page 106.



                documentclassarticle
                defsigned #1 (#2)unskipnobreakhfilpenalty50
                hskip2emhboxnobreakhfilsl#1/ rm(#2)
                parfillskip=0pt finalhyphendemerits=0 par
                begindocument
                hsize 9cm
                This is a case where the name and address fit in nicely with the review.
                signed A. Reviewer (Ann Arbor, Mich.)

                But sometimes an extra line must be added. signed N. Bourbaki (Paris)
                enddocument


                output



                You could make it a bit more standard for LaTeX:



                documentclassarticle
                newcommandsigned[1]%
                unskipnobreakhfilpenalty50
                hskip2emhboxnobreakhfil#1
                parfillskip=0pt finalhyphendemerits=0 par
                begindocument
                hsize 9cm
                This is a case where the name and address fit in nicely with the review.
                signedemphA. Reviewer (Ann Arbor, Mich.)

                But sometimes an extra line must be added. signedemphN. Bourbaki (Paris)
                enddocument


                And the explanation of how it works from The TeXbook:




                If a line break occurs at the penalty50, the hskip2em will disappear
                and the empty hbox will occur at the beginning of a line, followed by
                hfil glue. This yields two lines whose badness is zero; the first of
                these lines is assessed a penalty of 50. But if no line break occurs
                at the penalty50, there will be glue of 2 em plus 2 fil between the
                review and the name; this yields one line of badness zero. TEX will
                try both alternatives, to see which leads to the fewest total
                demerits. The one-line solution will usually be preferred if it is
                feasible.







                share|improve this answer















                There is a nice example in The TeXbook to do this. See chapter 14, page 106.



                documentclassarticle
                defsigned #1 (#2)unskipnobreakhfilpenalty50
                hskip2emhboxnobreakhfilsl#1/ rm(#2)
                parfillskip=0pt finalhyphendemerits=0 par
                begindocument
                hsize 9cm
                This is a case where the name and address fit in nicely with the review.
                signed A. Reviewer (Ann Arbor, Mich.)

                But sometimes an extra line must be added. signed N. Bourbaki (Paris)
                enddocument


                output



                You could make it a bit more standard for LaTeX:



                documentclassarticle
                newcommandsigned[1]%
                unskipnobreakhfilpenalty50
                hskip2emhboxnobreakhfil#1
                parfillskip=0pt finalhyphendemerits=0 par
                begindocument
                hsize 9cm
                This is a case where the name and address fit in nicely with the review.
                signedemphA. Reviewer (Ann Arbor, Mich.)

                But sometimes an extra line must be added. signedemphN. Bourbaki (Paris)
                enddocument


                And the explanation of how it works from The TeXbook:




                If a line break occurs at the penalty50, the hskip2em will disappear
                and the empty hbox will occur at the beginning of a line, followed by
                hfil glue. This yields two lines whose badness is zero; the first of
                these lines is assessed a penalty of 50. But if no line break occurs
                at the penalty50, there will be glue of 2 em plus 2 fil between the
                review and the name; this yields one line of badness zero. TEX will
                try both alternatives, to see which leads to the fewest total
                demerits. The one-line solution will usually be preferred if it is
                feasible.








                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 12 '18 at 13:48

























                answered Nov 12 '18 at 13:37









                David PurtonDavid Purton

                9,0751835




                9,0751835



























                    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%2f459594%2falign-last-word-of-a-paragraph-to-the-right%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

                    Use pre created SQLite database for Android project in kotlin

                    Darth Vader #20

                    Ondo