# How to set the spacing before and after of section headings to a fixed value of 1.5cm?

In this code, i want the spacing before and after of my section, subsection, and subsubsection headings to be exactly 1.5cm regardless of the font size or my line spacing. How can i do this?
I know that this question has been asked before several times on this site but I want a package-free solution.

\documentclass[a4paper]{book}
\usepackage{lipsum}
\begin{document}
\chapter{A Chapter}
\lipsum[2]
\section{Foo}
\lipsum[2]
\subsection{Bar}
\lipsum[2]
\subsubsection{Foo Bar}
\lipsum[2]
\end{document}


# Edit

I know that the spacing before, say, section headings is controlled by the code below, but when I enter -1.5cm instead of -3.25ex, the vertical space before the heading doesn't become exactly 1.5cm on the output. Why?

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

• Are you use -1.5cm \@plus -1ex \@minus -.2ex?
– Werner
Jan 21 '15 at 17:17
• Is there a reason for not using a package? There is no real difference between the code coming from a package and the code you are writing into your document. It could even be much more trouble without a package. Jan 21 '15 at 17:25
• @Werner: Yes, I do, but the space is not exact on the output. Jan 21 '15 at 17:30
• @Sisabe because you are using stretchable glue Jan 21 '15 at 17:30
• @Sisabe: When use add the \@plus and \@minus, you allow for 1.5cm to increase by 1ex or decrease by .2ex (see What is glue stretching?). If you use only -1.5cm, you should get a fixed skip of 1.5cm from the baseline of the last paragraph to the top of the baseline of the section title.
– Werner
Jan 21 '15 at 17:52

The package free solution, just using another document class ;-)

\documentclass[a4paper,emulatestandardclasses]{scrbook}
\usepackage{lipsum}
\RedeclareSectionCommands[%
beforeskip=-1.5cm,%
afterskip=1.5cm%
]{section,subsection,subsubsection}
\begin{document}
\chapter{A Chapter}
\lipsum[2]
\section{Foo}
\lipsum[2]
\subsection{Bar}
\lipsum[2]
\subsubsection{Foo Bar}
\lipsum[2]
\end{document}

• I'm talking about the book class, not scrbook. Jan 21 '15 at 17:41
• @Sisabe I saw that, that's why there is the smiley and the option emulatestandardclasses to make no visual difference as everything is taken over from the standardclasses. Jan 21 '15 at 17:56