# Ragged Right linebreaking, such that the last line is fullest, and the first most empty

using \raggedright roughly speaking will result in linebreaking when ever there is not enough space on the line to put the next word. This in turn results in all lines, except the last, being mostly full.

I want to achieve the opposite. I wish for the last line to be full, and the first line to be partially empty.

In the example below I have achieved this for the second heading using manual line breaking.

\documentclass{article}
\begin{document}

\begin{minipage}{3cm}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi.\\
\bigskip

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi.
\end{minipage}
\end{document}


\documentclass{article}
\begin{document}

\begin{minipage}{3cm}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi.
\end{minipage}
\end{document}


The above ensures that on the last line there is no stretch glue added so it is always fully justified. This may not be desired in all cases, specifically if the paragraph is single line you probably want a flush left setting and also if the last line is short you may prefer it to be ragged rather than over-stretch to justify. You can add \hspace*{\fill} at the end of the text in these cases, but below is a more complicated version but sets the heading in a box so that it can remove the last line of the paragraph and in the case the paragraph had just one line, or the natural length of the last line is less than 80% of the line width, then the last line is set at its natural width, flush left and the justified last line is discarded.

\documentclass{article}
\begin{document}

\xdef\tmpdepth{\prevdepth\the\prevdepth}%
\setbox0\vbox{{%
\tmpdepth
\bfseries\raggedright\parfillskip=-\rightskip #1\par
\xdef\tmpdepth{\prevdepth\the\prevdepth}%
\setbox0\lastbox
\setbox2\hbox{\unhcopy0}%
\nointerlineskip
\ifnum\prevgraf=1 \box2 \else
\ifdim\wd2<.8\wd0 \box2 \else
\box0
\fi\fi
}}%
\unvbox0
\tmpdepth
}% why not define as a heading?
\begin{minipage}{3cm}
Lorem ipsum dolor sit amet, consectetur adipiscing elit,

Lorem ipsum dolor sit amet, consectetur adipiscing elit,

\myheading{This is much longer and covers several lines igs}
Lorem ipsum dolor sit amet, consectetur adipiscing elit,

\myheading{This is much much longer and covers several lines igs}
Lorem ipsum dolor sit amet, consectetur adipiscing elit,


• Doesn't quiet work right, if the heading is only on one line. try: \myheading{short head} It is not ragged, it is kinda justified (via interword spacing) – Lyndon White Mar 8 '18 at 7:22
• I am messing around with it, \hfill doesn't help at all. (I'm trying ragged2e but that doesn't work ideally for \myheading{medium len head} which it breaks unnecessarily – Lyndon White Mar 8 '18 at 8:04