When typesetting paragraphs, I want to ensure their last line is neither overly short nor overly long. To that end, I'm looking for settings that produce either:
- a fully justified, perfectly rectangular paragraph;
- a justified paragraph whose last line is filled more than 20% and less than 80%.
In other words, no paragraph should have a last line that is filled for less than 20% or more than 80%—they should become fully justified instead. The effect could be achieved by manually adding \parfillskip 0pt
to (only) those paragraphs, but this is exactly what I want to automate instead.
This document shows two good examples and two bad examples:
\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
% Page setup
\usepackage[a4paper,margin=3cm]{geometry}
% Typography
\usepackage{newtxtext,newtxmath}
\usepackage{microtype}
\parindent 0pt
\parskip\baselineskip
\begin{document}
\textbf{I'm looking for settings
that produce either a)~a~perfect rectangle
or b)~a paragraph whose last line
is filled more than 20\% and less than 80\%.}
\section*{Good examples}
\textbf{My perfect paragraph is a~rectangle:}
{
\parfillskip 0pt
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed rhoncus lorem eget ultricies bibendum. Duis luctus felis arcu, sit amet dapibus orci imperdiet id. Duis ullamcorper tortor eget leo fringilla, a lacinia nisl pulvinar. Etiam id facilisis augue. Sed convallis tempus ex, sed accumsan justo pulvinar vitae. Sed id sapien leo. Aliquam posuere ex lacus, ut posuere metus ullamcorper eu. Duis a imperdiet nibh. Donec tincidunt hendrerit nulla, et convallis metus imperdiet nec. Pellentesque massa enim, pharetra in pulvinar a, efficitur nec lorem. Cras mattis ex lorem, et euismod ligula rhoncus. Aenean ultricies quis velit non faucibus.
}
\textbf{However, this is not always achievable (and that's fine):}
{
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed rhoncus lorem eget ultricies bibendum. Duis luctus felis arcu, sit amet dapibus orci imperdiet id. Duis ullamcorper tortor eget leo fringilla, a lacinia nisl pulvinar. Etiam id facilisis augue. Sed convallis tempus ex, sed accumsan justo pulvinar vitae. Sed id sapien leo. Aliquam posuere ex lacus, ut posuere metus ullamcorper eu. Duis a imperdiet nibh. Donec tincidunt hendrerit nulla, et convallis metus imperdiet nec. Pellentesque massa enim, pharetra in pulvinar a, efficitur nec lorem. Cras mattis ex lorem, et euismod ligula rhoncus.
}
\section*{Bad examples}
\textbf{This last line is too short:}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed rhoncus lorem eget ultricies bibendum. Duis luctus felis arcu, sit amet dapibus orci imperdiet id. Duis ullamcorper tortor eget leo fringilla, a lacinia nisl pulvinar. Etiam id facilisis augue. Sed convallis tempus ex, sed accumsan justo pulvinar vitae. Sed id sapien leo. Aliquam posuere ex lacus, ut posuere metus ullamcorper eu. Duis a imperdiet nibh. Donec tincidunt hendrerit nulla, et convallis metus imperdiet nec. Pellentesque massa enim, pharetra in pulvinar a, efficitur nec lorem.
\textbf{The above can be fixed with}
\verb!\parfillskip 0pt plus 0.80\textwidth!
\textbf{but that doesn't help for the case below.}
\textbf{This last line should have been justified (note the small gap at the end):}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed rhoncus lorem eget ultricies bibendum. Duis luctus felis arcu, sit amet dapibus orci imperdiet id. Duis ullamcorper tortor eget leo fringilla, a lacinia nisl pulvinar. Etiam id facilisis augue. Sed convallis tempus ex, sed accumsan justo pulvinar vitae. Sed id sapien leo. Aliquam posuere ex lacus, ut posuere metus ullamcorper eu. Duis a imperdiet nibh. Donec tincidunt hendrerit nulla, et convallis metus imperdiet nec. Pellentesque massa enim, pharetra in pulvinar a, efficitur nec lorem. Cras mattis ex lorem, et euismod ligula rhoncus. Aenean ultricies quis velit non ut faucibus.
\textbf{The above can be fixed with}
\verb!\parfillskip 0pt!
\textbf{but that doesn't help for the case below.}
\end{document}
A solution should consist of adjustments in the preamble only. No special commands should be required at the beginning or end of any paragraph. I hope that, as in several related cases, it can be solved with a special bit of glue in \parfillskip
, but I'm not sure whether this is possible.
Related questions, whose solutions I have tried but do not produce the intended output:
- Avoid just nearly filled last lines solves long last lines, but not short ones.
- Minimum length of last line of a paragraph solves short last lines, but not long ones.
- Is there a tool that makes paragraphs into rectangles? too strongly prefers rectangles, even if the last line is only filled half, with excessive interword spacing as a result.
\mbox
, place the last several words of the paragraph and a\hspace{.2\linewidth}
, so that your 1st paragraph (inarticle
class) would beWhen typesetting paragraphs, I want to ensure their last line is neither overly short nor overly long. To that end, I'm looking for settings \mbox{that produce either:\hspace{.2\linewidth}}
– Steven B. Segletes Apr 14 '17 at 11:46\parfilskip0pt
to selected paragraphs would also work, but I want TeX to apply this automatically to paragraphs with small or long last liens. – Ruben Verborgh Apr 14 '17 at 11:48