Spacing before and after section titles

Using the titlesec package you can use \titlespacing* you can change the spacing before and after the title; the syntax of the command is:

\titlespacing*{<command>}{<left>}{<before-sep>}{<after-sep>}

(there's an additional optional argument, but it's not important here). <left> increases the left margin; <before-sep> controls the vertical space before the title; <after-sep> controls the vertical space after the title. (Please refer to the package documentation for further information). A complete example:

\documentclass[10pt]{book}
\usepackage{titlesec}
\usepackage{lipsum}% just to generate text for the example

\titlespacing*{\section}
{0pt}{5.5ex plus 1ex minus .2ex}{4.3ex plus .2ex}
\titlespacing*{\subsection}
{0pt}{5.5ex plus 1ex minus .2ex}{4.3ex plus .2ex}

\begin{document}

\chapter{Kapitel 1}
\lipsum[4]
\section{Einleitung}
\lipsum[4]
\subsection{Motivation}
\lipsum[4]

\end{document}

enter image description here

I used ex (approximately the height of an "x" in the current font) as the unit for the lengths used, but you can use instead any other valid LaTeX unit (cm, in, mm, pt, among others); you can also use multiples of predefined lengths such as \baselineskip:

\titlespacing*{\subsection}
  {0pt}{2\baselineskip}{3\baselineskip}

I used ex since in this way the space is font-dependent. If you want to change the formatting of the titles, you can also use the same package and its powerful \titleformat command.


If you don't need all the "baggage" of an additional package like titlesec, you can simply modify these aspects of your headings yourself. See this example. I use a few sections and save the original section definition, so we can see a comparison.

I then define and use a section "prelude" prior to the invocation of the original section command. Then I add a "postlude" to the sectioning command. The prelude and the postlude here both add an extra em of vertical space, but you could use it to put in other sectioning highlights like rules, etc.

\documentclass{article}
\begin{document}
\section{First Section}

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

\section{Second Section}

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

\makeatletter
\let\origsection\section
\renewcommand\section{\@ifstar{\starsection}{\nostarsection}}

\newcommand\nostarsection[1]
{\sectionprelude\origsection{#1}\sectionpostlude}

\newcommand\starsection[1]
{\sectionprelude\origsection*{#1}\sectionpostlude}

\newcommand\sectionprelude{%
  \vspace{1em}
}

\newcommand\sectionpostlude{%
  \vspace{1em}
}
\makeatother

\section{Next Section}
Did this text drop 1em lower relative to the heading than the prior
section?  If so, we have succeeded.

\section{Final Section}

And the result is permananent, as you can see.

\end{document}

enter image description here


In case anybody wants to adjust the spaces while using KOMAscript -- @gonzalo's answer is not recommended since KOMA and titlesec are incompatible. However, KOMA provides commands to modify the section commands. The command

\RedeclareSectionCommand[beforeskip=-5.5ex plus -1ex minus -.2ex,afterskip=4.3ex plus -.2ex]{section}

modifies the space before and after a section title to similar values.