[Tex/LaTex] New line right aligned

horizontal alignment

What I'm trying to do is right-align a new line. In other words, I want to have a block of justified text, as normal, and then I wish to have a line break, with the new line right-aligned like this:

|Lorem ipsum dolor sit amet, consectetur adipiscing elit,|
|sed do eiusmod tempor incididunt ut labore et dolore ma-|
|gna aliqua.                                             |
|                                                    Text|

If the pipes indicate the margins (hyphenation may not respect Latin hyphenation rules, this is just a quick and dirty demonstration).

I tried using the flushright environment, but this, of course, starts a new paragraph, which I do not want:

\documentclass[12pt]{article}
\pagestyle{plain}
\usepackage[margin=1.8cm]{geometry}
\geometry{a4paper}
\usepackage[parfill]{parskip}
\usepackage{amsmath}
\usepackage{amssymb}

\begin{document}

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua.
\begin{flushright}
  Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
  eiusmod tempor incididunt ut labore et dolore magna aliqua.
\end{flushright}

\end{document}

enter image description here

I also tried to use the \raggedleft declaration, but if I try scoping it:

Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. \\
{\raggedleft Text}

It does not right-align Text at all.

I also tried using the \hfill command. This does not seem to work at the beginning of a new line, but I was able to quick-and-dirty my way around that problem. Nevertheless, \hfill doesn't quite fill the whole line, for some reason, leaving me with far-from right-aligned Text:

\documentclass[12pt]{article}
\pagestyle{plain}
\usepackage[margin=1.8cm]{geometry}
\geometry{a4paper}
\usepackage[parfill]{parskip}
\usepackage{amsmath}
\usepackage{amssymb}

\begin{document}

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. \\
\hspace*{0pt}\hfill Text

\end{document}

enter image description here

Possible complications

Firstly, I would, ideally, like to be able to use any solution within an enumerate environment.

Secondly, I was initially trying to define a command for a logical structure. I began with:

\newcommand{\grade}[1]{\newline\textbf{Grade} #1}

And then thought it would look better if I could right-align the grade. As such, ideally, I would like a solution that can be incorporated into the definition of a new command.

Best Answer

Issue \par\nopagebreak under zero \parskip, which is obtained by using a group, so the value of \parskip will be restored at \endgroup.

\documentclass[12pt]{article}

\usepackage[parfill]{parskip}

\newcommand{\lastline}[1]{%
  \begingroup\setlength{\parskip}{0pt}\par\nopagebreak
  \raggedleft#1\par\endgroup
}

\begin{document}

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. 
\lastline{Some text that's flush right.}

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. 
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua.

\begin{enumerate}
\item Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua.
\lastline{Some text that's flush right.}

\item Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua.
\end{enumerate}

\end{document}

enter image description here