1

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 
daleif
  • 54,450
Sisabe
  • 3,351
  • Are you use -1.5cm \@plus -1ex \@minus -.2ex? – Werner Jan 21 '15 at 17:17
  • 1
    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. – Johannes_B Jan 21 '15 at 17:25
  • @Werner: Yes, I do, but the space is not exact on the output. – Sisabe Jan 21 '15 at 17:30
  • 1
    @Sisabe because you are using stretchable glue – Johannes_B Jan 21 '15 at 17:30
  • @Johannes_B: Yes. I am scared of side effects of packages, especially the titlesec package. – Sisabe Jan 21 '15 at 17:31
  • 1
    @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

1 Answers1

2

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}
Johannes_B
  • 24,235
  • 10
  • 93
  • 248
  • I'm talking about the book class, not scrbook. – Sisabe 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. – Johannes_B Jan 21 '15 at 17:56