1

I want to align the contents of a paragraph such that it is justified, BUT the white space at the end of the paragraph (on the last line) is moved inside the paragraph at a place where a \hfill-like command is issued. In this way, the last line of the paragraph will be full.

Is it possible?

Edit: I DO want to have a blank white space inside the paragraph. This can also appear on the last line. The main requirement is that the text after the added white space stretches as much as possible in the last line of the paragraph.

Normal paragraph

Desired result

0
2

I'm not sure what you're trying to achieve, but here's an attempt.

The “strange paragraph” is typeset in a suitable environment and, at the place where you'd like the space to appear you type \spacehere.

The paragraph is typeset once and the last line is measured against the line width, when \spacehere is just a no-op. Then we redefine it to issue the appropriate spacing command and retypeset the paragraph with \parfillskip set to zero.

\documentclass{article}
\usepackage{environ}


\makeatletter
\NewEnviron{strangepar}{%
  \def\spacehere{\@bsphack\@esphack}%
  \setbox\z@=\vbox{\BODY\par\global\setbox\@ne\lastbox}%
  \setbox\z@=\hbox{\unhbox\@ne}%
  \strangeparfill=\dimexpr\linewidth-\wd\z@\relax
  \def\spacehere{\@bsphack\hspace*{\strangeparfill}\@esphack}%
  \par\BODY\parfillskip=0pt\par
}
\newlength\strangeparfill
\makeatother

\begin{document}

Nulla malesuada porttitor diam. Donec felis erat, congue non, volutpat at, 
tincidunt tristique, libero. Vivamus viverra fermentum felis. Donec nonummy 
pellentesque ante. Phasellus adipiscing semper elit. Proin fermentum massa 
ac quam. Sed diam turpis, molestie vitae, placerat a, molestie nec, leo. 
Maecenas lacinia. Nam ipsum ligula, eleifend at, accumsan nec, suscipit a, 
ipsum. Morbi blandit ligula feugiat magna. Nunc eleifend consequat lorem. 
Sed lacinia nulla vitae enim. Pellentesque tincidunt purus vel magna. 
Integer non enim. Praesent euismod nunc eu purus. Donec bibendum quam in 
tellus. Nullam cursus pulvinar lectus. Donec et mi. Nam vulputate metus eu 
enim. Vestibulum pellentesque felis eu massa.

\begin{strangepar}
Nulla malesuada porttitor diam. Donec felis erat, congue non, volutpat at, 
tincidunt tristique, libero. Vivamus viverra fermentum felis. Donec nonummy 
pellentesque ante. Phasellus adipiscing semper elit. Proin fermentum massa 
ac quam. Sed diam turpis, molestie vitae, placerat a, molestie nec, leo. 
Maecenas lacinia. \spacehere Nam ipsum ligula, eleifend at, accumsan nec, suscipit a, 
ipsum. Morbi blandit ligula feugiat magna. Nunc eleifend consequat lorem. 
Sed lacinia nulla vitae enim. Pellentesque tincidunt purus vel magna. 
Integer non enim. Praesent euismod nunc eu purus. Donec bibendum quam in 
tellus. Nullam cursus pulvinar lectus. Donec et mi. Nam vulputate metus eu 
enim. Vestibulum pellentesque felis eu massa.
\end{strangepar}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.