Align last word of a paragraph to the right?
up vote
4
down vote
favorite
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
documentclass[12pt]{article}
begin{document}
noindenttextbf{In real document, I would use texttt{stringhfill} instead of texttt{stringhrulefill}. The latter just demonstrates it better in an example document.}
.
noindenttextbf{The command texttt{stringhfill} is useful for aligning short text to left and right easily.}
noindent Bla bla.
hrulefill Yada yada.
.
noindenttextbf{If 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.
.
noindenttextbf{Boxes don't help.}
noindent hbox{Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla.}
hrulefill hbox{Yada Yada Yada Yada Yada Yada Yada Yada Yada.}
.
noindenttextbf{What 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)
.
noindenttextbf{An 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)
end{document}
horizontal-alignment
add a comment |
up vote
4
down vote
favorite
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
documentclass[12pt]{article}
begin{document}
noindenttextbf{In real document, I would use texttt{stringhfill} instead of texttt{stringhrulefill}. The latter just demonstrates it better in an example document.}
.
noindenttextbf{The command texttt{stringhfill} is useful for aligning short text to left and right easily.}
noindent Bla bla.
hrulefill Yada yada.
.
noindenttextbf{If 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.
.
noindenttextbf{Boxes don't help.}
noindent hbox{Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla.}
hrulefill hbox{Yada Yada Yada Yada Yada Yada Yada Yada Yada.}
.
noindenttextbf{What 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)
.
noindenttextbf{An 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)
end{document}
horizontal-alignment
add a comment |
up vote
4
down vote
favorite
up vote
4
down vote
favorite
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
documentclass[12pt]{article}
begin{document}
noindenttextbf{In real document, I would use texttt{stringhfill} instead of texttt{stringhrulefill}. The latter just demonstrates it better in an example document.}
.
noindenttextbf{The command texttt{stringhfill} is useful for aligning short text to left and right easily.}
noindent Bla bla.
hrulefill Yada yada.
.
noindenttextbf{If 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.
.
noindenttextbf{Boxes don't help.}
noindent hbox{Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla.}
hrulefill hbox{Yada Yada Yada Yada Yada Yada Yada Yada Yada.}
.
noindenttextbf{What 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)
.
noindenttextbf{An 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)
end{document}
horizontal-alignment
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
documentclass[12pt]{article}
begin{document}
noindenttextbf{In real document, I would use texttt{stringhfill} instead of texttt{stringhrulefill}. The latter just demonstrates it better in an example document.}
.
noindenttextbf{The command texttt{stringhfill} is useful for aligning short text to left and right easily.}
noindent Bla bla.
hrulefill Yada yada.
.
noindenttextbf{If 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.
.
noindenttextbf{Boxes don't help.}
noindent hbox{Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla.}
hrulefill hbox{Yada Yada Yada Yada Yada Yada Yada Yada Yada.}
.
noindenttextbf{What 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)
.
noindenttextbf{An 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)
end{document}
horizontal-alignment
horizontal-alignment
asked yesterday
kdb
808514
808514
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
5
down vote
There is a nice example in The TeXbook to do this. See chapter 14, page 106.
documentclass{article}
defsigned #1 (#2){{unskipnobreakhfilpenalty50
hskip2emhbox{}nobreakhfilsl#1/ rm(#2)
parfillskip=0pt finalhyphendemerits=0 par}}
begin{document}
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)
end{document}
You could make it a bit more standard for LaTeX:
documentclass{article}
newcommand{signed}[1]{%
{unskipnobreakhfilpenalty50
hskip2emhbox{}nobreakhfil#1
parfillskip=0pt finalhyphendemerits=0 par}}
begin{document}
hsize 9cm
This is a case where the name and address fit in nicely with the review.
signed{emph{A. Reviewer} (Ann Arbor, Mich.)}
But sometimes an extra line must be added. signed{emph{N. Bourbaki} (Paris)}
end{document}
And the explanation of how it works from The TeXbook:
If a line break occurs at the
penalty50
, thehskip2em
will disappear
and the emptyhbox
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 of50
. But if no line break occurs
at thepenalty50
, there will be glue of2 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.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
There is a nice example in The TeXbook to do this. See chapter 14, page 106.
documentclass{article}
defsigned #1 (#2){{unskipnobreakhfilpenalty50
hskip2emhbox{}nobreakhfilsl#1/ rm(#2)
parfillskip=0pt finalhyphendemerits=0 par}}
begin{document}
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)
end{document}
You could make it a bit more standard for LaTeX:
documentclass{article}
newcommand{signed}[1]{%
{unskipnobreakhfilpenalty50
hskip2emhbox{}nobreakhfil#1
parfillskip=0pt finalhyphendemerits=0 par}}
begin{document}
hsize 9cm
This is a case where the name and address fit in nicely with the review.
signed{emph{A. Reviewer} (Ann Arbor, Mich.)}
But sometimes an extra line must be added. signed{emph{N. Bourbaki} (Paris)}
end{document}
And the explanation of how it works from The TeXbook:
If a line break occurs at the
penalty50
, thehskip2em
will disappear
and the emptyhbox
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 of50
. But if no line break occurs
at thepenalty50
, there will be glue of2 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.
add a comment |
up vote
5
down vote
There is a nice example in The TeXbook to do this. See chapter 14, page 106.
documentclass{article}
defsigned #1 (#2){{unskipnobreakhfilpenalty50
hskip2emhbox{}nobreakhfilsl#1/ rm(#2)
parfillskip=0pt finalhyphendemerits=0 par}}
begin{document}
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)
end{document}
You could make it a bit more standard for LaTeX:
documentclass{article}
newcommand{signed}[1]{%
{unskipnobreakhfilpenalty50
hskip2emhbox{}nobreakhfil#1
parfillskip=0pt finalhyphendemerits=0 par}}
begin{document}
hsize 9cm
This is a case where the name and address fit in nicely with the review.
signed{emph{A. Reviewer} (Ann Arbor, Mich.)}
But sometimes an extra line must be added. signed{emph{N. Bourbaki} (Paris)}
end{document}
And the explanation of how it works from The TeXbook:
If a line break occurs at the
penalty50
, thehskip2em
will disappear
and the emptyhbox
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 of50
. But if no line break occurs
at thepenalty50
, there will be glue of2 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.
add a comment |
up vote
5
down vote
up vote
5
down vote
There is a nice example in The TeXbook to do this. See chapter 14, page 106.
documentclass{article}
defsigned #1 (#2){{unskipnobreakhfilpenalty50
hskip2emhbox{}nobreakhfilsl#1/ rm(#2)
parfillskip=0pt finalhyphendemerits=0 par}}
begin{document}
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)
end{document}
You could make it a bit more standard for LaTeX:
documentclass{article}
newcommand{signed}[1]{%
{unskipnobreakhfilpenalty50
hskip2emhbox{}nobreakhfil#1
parfillskip=0pt finalhyphendemerits=0 par}}
begin{document}
hsize 9cm
This is a case where the name and address fit in nicely with the review.
signed{emph{A. Reviewer} (Ann Arbor, Mich.)}
But sometimes an extra line must be added. signed{emph{N. Bourbaki} (Paris)}
end{document}
And the explanation of how it works from The TeXbook:
If a line break occurs at the
penalty50
, thehskip2em
will disappear
and the emptyhbox
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 of50
. But if no line break occurs
at thepenalty50
, there will be glue of2 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.
There is a nice example in The TeXbook to do this. See chapter 14, page 106.
documentclass{article}
defsigned #1 (#2){{unskipnobreakhfilpenalty50
hskip2emhbox{}nobreakhfilsl#1/ rm(#2)
parfillskip=0pt finalhyphendemerits=0 par}}
begin{document}
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)
end{document}
You could make it a bit more standard for LaTeX:
documentclass{article}
newcommand{signed}[1]{%
{unskipnobreakhfilpenalty50
hskip2emhbox{}nobreakhfil#1
parfillskip=0pt finalhyphendemerits=0 par}}
begin{document}
hsize 9cm
This is a case where the name and address fit in nicely with the review.
signed{emph{A. Reviewer} (Ann Arbor, Mich.)}
But sometimes an extra line must be added. signed{emph{N. Bourbaki} (Paris)}
end{document}
And the explanation of how it works from The TeXbook:
If a line break occurs at the
penalty50
, thehskip2em
will disappear
and the emptyhbox
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 of50
. But if no line break occurs
at thepenalty50
, there will be glue of2 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.
edited yesterday
answered yesterday
David Purton
7,8341834
7,8341834
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%2f459594%2falign-last-word-of-a-paragraph-to-the-right%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