# Space between math env and section title

I have a problem with some extra space in a particular situation. Maybe it's a really easy problem, but unfortunately I have no experience and perhaps you should redirect me to some good documentation to control vertical space after title, code block, math block, etc...

I wrote this :

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{titlesec}
\usepackage{amsmath}

\titlespacing{\section}{0pt}{0pt}{0pt}
\titlespacing{\subsection}{0pt}{0pt}{0pt}

\begin{document}

\section*{Trigonometrie}
text text text text text text
\begin{gather*}
\cos(a+b)=\cos(a)\cos(b)-\sin(a)\sin(b) \\
\cos(a-b)=\cos(a)\cos(b)+\sin(a)\sin(b) \\
\sin(a+b)=\sin(a)\cos(b)+\sin(b)\cos(a) \\
\sin(a-b)=\sin(a)\cos(b)-\sin(b)\cos(a) \\
\tan(a+b)=\frac{\tan(a)+\tan(b)}{1-\tan(a)\tan(b)} \\
\tan(a-b)=\frac{\tan(a)-\tan(b)}{1+\tan(a)\tan(b)}
\end{gather*}

\end{document}


And it looks like this, which is fine :

But when I delete the "text text text" line, the math block just stay in the same position, and the extra space is really annoying between the section title and the block. I really want to control space between title, text and equation, but it seems to be really hard.

• Welcome to TeX - LaTeX! This doesn't answer the question, but usually it is better to have glue specification rather an absolute length. Dec 16, 2017 at 19:38

Math displays should never be at the beginning of a paragraph; in this case spurious vertical spacing appears.

In your case this is wanted, so you can do it by properly starting a paragraph and then backing up by a baseline skip.

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{titlesec}
\usepackage{amsmath}

\titlespacing{\section}{0pt}{0pt}{0pt}
\titlespacing{\subsection}{0pt}{0pt}{0pt}

\begin{document}

\section*{Trigonometrie}

\mbox{}\vspace*{-\baselineskip}
\begin{gather*}
\begin{aligned}
\cos(a+b)&=\cos(a)\cos(b)-\sin(a)\sin(b) \\
\cos(a-b)&=\cos(a)\cos(b)+\sin(a)\sin(b) \\
\sin(a+b)&=\sin(a)\cos(b)+\sin(b)\cos(a) \\
\sin(a-b)&=\sin(a)\cos(b)-\sin(b)\cos(a)
\end{aligned}\\
\tan(a+b)=\frac{\tan(a)+\tan(b)}{1-\tan(a)\tan(b)} \\
\tan(a-b)=\frac{\tan(a)-\tan(b)}{1+\tan(a)\tan(b)}
\end{gather*}

\end{document}


By the way, with a nested aligned environment, you can get better alignment for the first four formulas.

I wouldn't remove also the remaining vertical spaces.

The easy solution is to use \vspace command:

\documentclass{article}
\usepackage{amsmath}
\title{Here is a title}

\begin{document}
\section*{Trigonometrie}
\begin{gather*}
\cos(a+b)=\cos(a)\cos(b)-\sin(a)\sin(b) \\
\cos(a-b)=\cos(a)\cos(b)+\sin(a)\sin(b) \\
\sin(a+b)=\sin(a)\cos(b)+\sin(b)\cos(a) \\
\sin(a-b)=\sin(a)\cos(b)-\sin(b)\cos(a) \\
\tan(a+b)=\frac{\tan(a)+\tan(b)}{1-\tan(a)\tan(b)} \\
\tan(a-b)=\frac{\tan(a)-\tan(b)}{1+\tan(a)\tan(b)}
\end{gather*}
\end{document}


Another option is to change \abovedisplayskip

\documentclass{article}
\usepackage{amsmath}
\title{Here is a title}

\begin{document}
{
\setlength{\abovedisplayskip}{-8pt}
\section*{Trigonometrie}
\begin{gather*}
\cos(a+b)=\cos(a)\cos(b)-\sin(a)\sin(b) \\
\cos(a-b)=\cos(a)\cos(b)+\sin(a)\sin(b) \\
\sin(a+b)=\sin(a)\cos(b)+\sin(b)\cos(a) \\
\sin(a-b)=\sin(a)\cos(b)-\sin(b)\cos(a) \\
\tan(a+b)=\frac{\tan(a)+\tan(b)}{1-\tan(a)\tan(b)} \\
\tan(a-b)=\frac{\tan(a)-\tan(b)}{1+\tan(a)\tan(b)}
\end{gather*}
}

other text here doesn't have affect by the changed length because the change is inside a group.

\begin{gather*}
\cos(a+b)=\cos(a)\cos(b)-\sin(a)\sin(b) \\
\cos(a-b)=\cos(a)\cos(b)+\sin(a)\sin(b) \\
\sin(a+b)=\sin(a)\cos(b)+\sin(b)\cos(a) \\
\sin(a-b)=\sin(a)\cos(b)-\sin(b)\cos(a) \\
\tan(a+b)=\frac{\tan(a)+\tan(b)}{1-\tan(a)\tan(b)} \\
\tan(a-b)=\frac{\tan(a)-\tan(b)}{1+\tan(a)\tan(b)}
\end{gather*}
\end{document}


Both solutions gives the above of the figure:

• I was aware about the vspace command but I was searching a solution to control the space each time I will place a math block next to a section. I think I should search and understand how the \abovedisplayskip work. Thank you
– Mahé
Dec 16, 2017 at 19:37
• Welcome... If you want to keep the change for the next of the text just place the command outside of the group (don't create a group and enclose it) Dec 16, 2017 at 19:42