10

To avoid widow words at the last line of a paragraph, I adjust parfillskip:

\parfillskip 0pt plus 0.75\textwidth

While this gives nicer paragraphs, it also stretches section titles a little, as you can see below. The first title is with the default parfillskip, the second with 0pt plus 0.75\textwidth:

How can I keep my parfillskip setting for paragraphs, but not for titles?

This code showcases the effect for text and titles (preview):

\documentclass{article}
\usepackage{lipsum}
\begin{document}
\section{This is a section title}
\lipsum[1]
\section{This is a section title}

% Fill the last line of paragraphs for minimum 25%
\parfillskip 0pt plus 0.75\textwidth
\section{This is a section title}
\lipsum[1]
\end{document}
  • My impression is that you create more paragraphing problems than you solve, with that setting of \parfillskip. – egreg Dec 29 '13 at 17:32
  • @egreg I'm quite happy with what it does to the paragraphs actually; just not do the titles: i.imgur.com/YAVeaTu.png But other suggestions to achieve the same effect with paragraphs are welcome. – Ruben Verborgh Dec 29 '13 at 18:30
9

The section title is typeset by \@sect, which happily encloses the relevant part in a group. At the end it adds \@@par, which is the primitive \par.

Thus we can safely patch \@sect:

\documentclass{article}

\usepackage{etoolbox}
\makeatletter
\patchcmd{\@sect}{\begingroup}{\begingroup\parfillskip=0pt plus 1fil\relax}{}{}
\makeatother

\usepackage{lipsum}
\begin{document}
\section{This is a section title}
\lipsum[1]

% Fill the last line of paragraphs for minimum 25%
\parfillskip 0pt plus 0.75\textwidth
\section{This is a section title}
\lipsum[1]
\end{document}

enter image description here

  • 1
    Great! Note that this solution also works for \subsection (despite what \@sect might make you think). – Ruben Verborgh Dec 29 '13 at 20:24
1

For the memoir class, it suffices to add to the preamble:

\setsecheadstyle{\Large\parfillskip=0pt plus 1fil}
  • 1
    And for KOMA-Script classes you do not need to do anything, because they already support \parfillskip > 0. – Schweinebacke Mar 10 '17 at 11:37

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.