# Make \section unaffected by \parfillskip

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

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}


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

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

\setsecheadstyle{\Large\parfillskip=0pt plus 1fil}

• 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