3

I am using the parskip package for two reasons:

  1. To add a space between paragraphs.
  2. To remove the indentation of a first line in a paragraph.

However, this package makes the spacing before and after a subsection heading be absurdly wide. I have tried using the \titlespacing macro from the titlesec package to modify that whitespace, but it seems like the other package rules out this one. It just isn't taking any effect.

How can I reduce that space?

Johannes_B
  • 24,235
  • 10
  • 93
  • 248
dabadaba
  • 263
  • Take my answer at http://tex.stackexchange.com/questions/108684/spacing-before-and-after-section-titles/108824#108824 and do three things: 1) add \usepackage{parskip}; 2) change all occurrences of section to subsection; and 3) change the prelude and postlude definitions to something with negative \vspace as for example, \newcommand\subsectionprelude{\vspace{-1em}} – Steven B. Segletes Aug 11 '16 at 11:34
  • Please, add a minimal example of what you have, particularly about ”the other package [which] rules out" titlesec – egreg Aug 12 '16 at 07:33
  • @egreg The issue is solved, and I did say what "the other package" is (titlesec). – dabadaba Aug 12 '16 at 09:54

2 Answers2

2

Following the advice of my comment (utilizing my answer at Spacing before and after section titles), but applying the result to subsections, and reducing the spacing.

EDITED to take Gustavo's suggestions: 1) implementing optional argument to \subsection; and 2) using -\parskip as the adjusted vertical height.

\documentclass{article}
\usepackage{parskip}
\begin{document}
\tableofcontents

\noindent\hrulefill

\section{Without Fix}

Blah blah 

\subsection{First subsection}

This is the first line of text.  Note the vertical spacing.  

\subsection{Second subsection}

Observe the spacing prior to and following the subsectioning command. Now let me
redefine a few things.

\makeatletter
\let\origsubsection\subsection
\renewcommand\subsection{\@ifstar{\starsubsection}{\nostarsubsection}}

\newcommand\nostarsubsection[2][\relax]{%
  \subsectionprelude%
  \ifx\relax#1\origsubsection{#2}\else\origsubsection[#1]{#2}\fi%
  \subsectionpostlude}

\newcommand\starsubsection[2][\relax]{%
  \subsectionprelude%
  \ifx\relax#1\origsubsection*{#2}\else\origsubsection*[#1]{#2}\fi%
  \subsectionpostlude}

\newcommand\subsectionprelude{%
  \vspace{-\parskip}% OR ANY OTHER DESIRED VALUE
}

\newcommand\subsectionpostlude{%
  \vspace{-\parskip}% OR ANY OTHER DESIRED VALUE
}
\makeatother

\section{With Fix}

Blah blah

\subsection[Alternate TOC title]{Next subsection}
Did this text raise parskip higher relative to the heading than the prior
subsection?  If so, we have succeeded.

\subsection*{Non-numbered subsection}

Here is some text.

\subsection{Final subsection}

And the result is permananent, as you can see.

\end{document}

enter image description here

0

For reasons that I cannot understand, Steven declined my suggestion of using xparse. However, I deem that an answer along these lines could be of some interest, so I am supplying it myself.

I’ll espouse Steven’s approach of making no assumption whatsoever on how \subsection is implemented:

% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly 
                                 % declare the paper format.

\usepackage[T1]{fontenc}         % Not always necessary, but recommended.
% End of standard header.  What follows pertains to the problem at hand.

\usepackage{parskip}
\usepackage{xparse}

\let \originalSubsection \subsection
\RenewDocumentCommand \subsection { s o m } {%
    \vspace{-\parskip}%
    \IfBooleanTF{#1}{%
        \originalSubsection*{#3}%
    }{%
        \IfValueTF{#2}{%
            \originalSubsection[#2]{#3}%
        }{%
            \originalSubsection{#3}%
        }%
    }%
    \vspace{-\parskip}%
}



\begin{document}

\tableofcontents

\section{With Fix}

Blah blah.

\subsection*{A starred subsection}
This subsection has no number, and is not included in the ToC\@.

\subsection{Normal subsection}
This subsection is normal in all respects: it is numbered, and appears in the 
ToC\@ with the same title as above.

\subsection[Short title]{A somewhat longer title}
Numbered subsection, but with a different title in the ToC\@.

\subsection*[Ignored argument]{This is possible too\ldots}
\ldots and it is a well-known issue; it doesn't hurt, anyway!

\end{document}
GuM
  • 21,558