11

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
10

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 (for numbered sections) and \@ssect (for unnumbered sections):

\documentclass{article}

\usepackage{etoolbox}
\makeatletter
\patchcmd{\@sect}{\begingroup}{\begingroup\parfillskip=0pt plus 1fil\relax}{}{}
\patchcmd{\@ssect}{\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

| improve this answer | |
  • 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
  • how can I apply this for section*? – Emit Taste Nov 3 at 22:28
  • 1
    @EmitTaste Apply the same patch to \@ssect. I added the code, thanks for noticing. – egreg Nov 3 at 22:29
1

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

\setsecheadstyle{\Large\parfillskip=0pt plus 1fil}
| improve this answer | |
  • 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
0

Since section titles should not be formatted with flush-right margins in any case -- despite the default document classes doing exactly that -- you should declare \raggedright in the definition of the sectioning; and once you do that, the \parfillskip is irrelevant.

Define the sectioning however you want:

  • with memoir or koma or other nice document class;
  • using a package like titlesec or some such;
  • with sectioning of the standard document classes using \@startsection
  • or, the most hackish, patch commands like \@sect

For example, the basic "article" class uses

\newcommand\section{\@startsection {section}{1}{\z@}%
                               {-3.5ex \@plus -1ex \@minus -.2ex}%
                               {2.3ex \@plus.2ex}%
                               {\normalfont\Large\bfseries}}

so a document setup could include a \renewcommand of that with \raggedright inserted in the font-style argument

\makeatletter
\renewcommand\section{\@startsection {section}{1}{\z@}%
                               {-3.5ex \@plus -1ex \@minus -.2ex}%
                               {2.3ex \@plus.2ex}%
                               {\normalfont\raggedright\Large\bfseries}}
| improve this answer | |

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.