# Spacing before and after section titles

I know this subject has been mentioned before, but I'm still having a problem in creating a space under a section title. I used the titlesec package and then tried using the command \titlespacing{\section}...

This is my code. Can anybody help?

\documentclass[10pt]{book}
\usepackage[utf8]{inputenc}
\usepackage{fullpage}
\usepackage[compact]{titlesec}
\usepackage{setspace}
\usepackage{sectsty}
\chapterfont{\huge}
\sectionfont{\Huge}
\begin{document}
\chapter*{Kapitel 1}
\section*{Einleitung}
\begin{large}
\subsection*{1.1 Motivation}

• Welcome to TeX.SX. A tip: If you indent lines by 4 spaces, then they're marked as a code sample. You can also highlight the code and click the "code" button ({}) or hit Ctrl+K. Apr 14, 2013 at 13:05
• Thanks! But sorry I didn't get what you mean. So leave the titlespacing and just use the \\ to make the spaces?
– abdu
Apr 14, 2013 at 13:56
• @user29019 but exactly what kind of space are you trying to get? Exactly how much space do you want after \chapter and \section? Apr 14, 2013 at 14:55
• @GonzaloMedina yes I tried it, it works. The \begin{large} is for the font size of the text. So everything is working till now. But I need create a titlespacing under the 'Einleitung' so between the section title und the text beneath it. I'm a new LaTeX user, I'm writing a scientific thesis. so there would be chapters, section and subsections. I searched in the internet for packages and commands I found things like \vspace, \titlespacing{\section}... but non of them worked, I compile the .tex file through a terminal (ubuntu) but I get no changes.
– abdu
Apr 14, 2013 at 16:16
• So I need like about 3 empty lines between section title and subsection title!
– abdu
Apr 14, 2013 at 16:20

## 4 Answers

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}


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.

• thanks very much! Everything worked, so now I know that I only have to use the titlesec package. I used the cm unit to change the spacing before the chapter and it worked! However I still have a problem, the one with the error. I can ignore it but it bothers while compiling through the terminal. I usually seperate two paragraphs with \\ \\ and this makes the error I think. Is there a way I can seperate paragraphs?
– abdu
Apr 15, 2013 at 11:08
• @abdu Yes, using two consecutive \\ commands will result in errors. You can use \par\bigskip instead at the end of each paragraph. Another option would be to load the parskip package which automatically suppresses indentation and increases separation between paragraphs. Yet another option would be to switch to the document class scrreprt and use its parskip features. Apr 15, 2013 at 12:49
• Why do you use parameters such as 5.5ex plus 1ex minus .2ex? Why not just 6.3ex? Nov 4, 2015 at 15:26
• @Adam_G The first option allows for stretching or shrinking; the second one, doesn't. Nov 4, 2015 at 17:46
• @Adam_G texdoc texbytopic (or The TeXbook) and search for glue. The answer to tex.stackexchange.com/q/64756/3954 can also give you an explanation. Nov 4, 2015 at 23:50

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}


• Hey thanks for your answer Steven. But I think I'll use the titlesec package just because I know how it works now. And since I'm using the report class I need chapters sections and subsections it's makes more sense to use the titlesec package. But thanks a lot, I'll save your code and try to use it in the future! =)
– abdu
Apr 15, 2013 at 11:01
• @abdu. I understand completely. It's just one more option, depending on the particular need. Apr 15, 2013 at 11:03
• Nice! How would this work if I wanted to do the same for \subsection*'s? Aug 9, 2016 at 13:52
• @texfan If you take my source and do a global search and replace from section to subsection, recompile and see the result. Aug 9, 2016 at 13:55
• @StevenB.Segletes Ah ok, I thought maybe there was a way to do both at once, but this works, thanks :)! Aug 10, 2016 at 9:49

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.

• This is a very important "detail" indeed! Note that the negative vale for beforeskip doesn't work too well, but the command itself is exactly what is needed when using e.g. \documentclass{scrartcl} May 1, 2021 at 13:56

To control each space individually you can simply use:

\vspace{5mm} or \vspace{1em} or \vspace{1cm} to increase (to add space) and;

\vspace{-5mm} or \vspace{-1em} or \vspace{-1cm} to decrease (take from the standard space).

It is most suitable to control few sections of the standard space.

Follow a working example:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{geometry}
\geometry{a4paper,
total={170mm,257mm},
left=20mm, top=20mm,}

\title{Spacing before and after section titles, \LaTeX}
\author{}
\date{}

\begin{document}

\maketitle

\section{\huge Increase \Large space between headings and text}

\subsection{With (\texttt{\textbackslash vspace\{4mm\}})}
\vspace{4mm}
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.

\subsection{With (\texttt{\textbackslash vspace\{0.5em\}})}
\vspace{0.5em}
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.

\subsection{With (\texttt{\textbackslash vspace\{0.6cm\}})}
\vspace{0.6cm}
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.

\vspace{1cm}
\hrulefill
\vspace{1cm}

\section{\huge Decrease \Large space between headings and text}

\subsection{With (\texttt{\textbackslash vspace\{-3.5mm\}})}
\vspace{-3.5mm}
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.

\subsection{With (\texttt{\textbackslash vspace\{-1em\}})}
\vspace{-1em}
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.

\subsection{With (\texttt{\textbackslash vspace\{-0.44cm\}})}
\vspace{-0.44cm}
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.

\end{document}


• it was tested here and works fine. Dec 2, 2020 at 17:21