[Tex/LaTex] Unwanted space after section title when using custom command

macrosspacingvertical

enter image description here

I have been using LaTeX for years now and I am usually able to answer my own questions myself or thanks to stack exchange. Until now. I have this strange vertical space appearing after the title of the section (see picture). It actually doesn't happen when I don't use my custom command \fillspace. But in a later subsection (not shown here), it doesn't happen even though I use the same command \fillspace, so it doesn't seem to be a regular problem. Strangely enough, it doesn't happen in the minimal sample code I give you with this question (the original code is for a 25-pages-long course…). The other command I created and used is \slv (which does the same as \\ but prevents the recurrent "no line to end here" error). I suspect that there is a subtle bug with my new commands but I just can't figure it out.

Do you know how I could remove this useless blank space? I can share the whole code with you, if needed.

Thanks in advance for any answer,

Bests,

Henri

\documentclass[a4paper, 12pt]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern} % load a font with all the characters
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{graphicx}
\usepackage{float}
\usepackage{stmaryrd}
\usepackage[margin=0.8in]{geometry}
\usepackage{amsfonts}
\usepackage{appendix}
\usepackage{wasysym}
\usepackage{pifont}
\newcommand{\slv}{\leavevmode\\}
\newcommand{\exo}{\vspace{0.1cm}\slv \ding{46}\textbf{\underline{Exercises}}: \\ \vspace{0.1cm}\slv }
\newcommand{\exm}{\vspace{0.1cm}\slv $\triangleright$ \textit{\underline{Examples}}: \\ \vspace{0.1cm}\slv }
\newcommand{\rem}{ \vspace{0.1cm}\slv $\bell$ \textbf{\underline{Remarks:}} }
\newcommand{\fillspace}[1]{\vspace{#1cm}\slv \checkmark\slv \vspace{#1cm}\slv}
\begin{document}

blablabla

\section{Second degree equations}
Among the equations that are still easily solvable are the second degree equations, which contain at least one second degree term and can generally be written\slv 
\fillspace{0.5}
These equations have between zero and two real solutions, as we will see later.\\
\exm 
1) Let us start from the equation $5x^2+3x-8=0$. We have\\
\vspace{1cm}\\
2) For the equation $2y^2+9=0$, we have\\
\vspace{1cm}\\
3) If we have something like $z^2-7z-3=5z^2-12$, we can transform the equation into\\
\vspace{1cm}\\
and thus we have\\blablabla...

\end{document}

enter image description here

Best Answer

I removed all the \\ from your example apart from the one case at the end where it was being used to mark a line break mid-paragraph (which is the only time it should be used) and the spacing is then more reasonable. It would be better to use the facilities for defining headings rather than just using underlined text and spacing as then latex will take care of page breaks around headings, but here I just concentrated on the spacing.

\documentclass[a4paper, 12pt]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern} % load a font with all the characters
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{graphicx}
\usepackage{float}
\usepackage{stmaryrd}
\usepackage[margin=0.8in]{geometry}
\usepackage{amsfonts}
\usepackage{appendix}
\usepackage{wasysym}
\usepackage{pifont}
%no!!! \newcommand{\slv}{\leavevmode\\}
\newcommand{\exo}{%
\par\vspace{0.1cm}%
\ding{46}\textbf{\underline{Exercises}}:\par\vspace{0.1cm}}
\newcommand{\exm}{%
\par\vspace{0.1cm}
$\triangleright$ \textit{\underline{Examples}}:\par
\vspace{0.1cm}}
\newcommand{\rem}{\par\vspace{0.1}$\bell$ \textbf{\underline{Remarks:}} }
\newcommand{\fillspace}[1]{\par\vspace{#1cm}\checkmark\par\vspace{#1cm}}
\begin{document}

blablabla

\section{Second degree equations}
Among the equations that are still easily solvable are the second degree equations, which contain at least one second degree term and can generally be written
\fillspace{0.5}
These equations have between zero and two real solutions, as we will see later.

\exm 
1) Let us start from the equation $5x^2+3x-8=0$. We have

\vspace{1cm}
2) For the equation $2y^2+9=0$, we have

\vspace{1cm}
3) If we have something like $z^2-7z-3=5z^2-12$, we can transform the equation into

\vspace{1cm}
and thus we have\\blablabla...

\end{document}
Related Question