Unwanted space after section title when using custom command

1,505

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}
Share:
1,505

Related videos on Youtube

Henri Degueldre
Author by

Henri Degueldre

Updated on August 01, 2022

Comments

  • Henri Degueldre
    Henri Degueldre over 1 year

    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

    • David Carlisle
      David Carlisle over 6 years
      all the \\ in this example are wrong, you should never have \\ at the end of a paragraph and certainly never after \vspace
  • Henri Degueldre
    Henri Degueldre over 6 years
    Ok, thanks for the help. I have to admit that I never used the command \par before, which is weird considering how useful it seems to be. I always overused the double backslash , apparently. I also modified my custom commands using the \paragraph structure, which is probably better. In my own answer that I will write below is my new code. It appears there are still places where I need to use the double backslash, such as in the tabular environment. What do you think?
  • David Carlisle
    David Carlisle over 6 years
    @HenriDegueldre yes \\ ends tabular and math alignment rows, but that's really a different command altogether, but it should almost never be used in running text. \par is just the same as a blank line (a blank line generates a \par token which is why it ends a paragraph, but in macros it is sometimes easier to write \par than use a blank line)
  • Henri Degueldre
    Henri Degueldre over 6 years
    Ok thanks a lot! This will definitely improve my TeX coding.