2

This is the problem: the "distance" between every subsubsection changes, according to how I end the previous subsubsection. If I end it with a text line, then it's ok. If I end it with a formula (between the \[ \]) then the next subsubsection is put at a bigger distance, and I need to use \vspace{-5mm}, to say.

How can I fix the distance to be the same, regardless of what I write in each subsubsection?

This is an example of the preamble I use, you can use it to see what I mean (but I add a screenshot too).

\documentclass[a4paper, 11pt]{scrreprt}
\usepackage{geometry}
\geometry{total={173mm, 257mm}, left=23mm, top=23mm, right=23mm, bottom=23mm}


\usepackage[bb=stixtwo]{mathalpha}


\usepackage{physics}
\usepackage{amsmath}
\usepackage{mathtools}

\usepackage{everysel}
\everymath{\color{red}}
\everydisplay{\color{red}}
\EverySelectfont{\color{black}}

%\usepackage{enumerate}
\usepackage{enumitem, xcolor}
\setlist[itemize]{label=\textcolor{red}{\textbullet}}
\setlist[enumerate]{label=\textcolor{red}{(\arabic*)}}


\usepackage{titlesec}
\titleformat{\section}[runin]
{\normalfont\Large\bfseries}{\thesection}{1em}{}
\titleformat{\subsection}[runin]
{\normalfont\large\bfseries\color{arsenic}}{\thesubsection}{1em}{}
\titleformat{\subsubsection}[runin]
{\normalfont\bfseries\color{black}}{\thesubsection}{1em}{}




\DeclareMathOperator{\lzp}{\displaystyle\lim_{x\to 0^+}}
\DeclareMathOperator{\lzm}{\displaystyle\lim_{x\to 0^-}}


\newcommand{\dint}{\displaystyle\int}
\newcommand{\dlim}{\displaystyle\lim}
\DeclareMathOperator{\dsum}{\displaystyle\sum}

\begin{document}

\subsubsection*{Exercise $1.$} Find the derivative of $f(x) = \sqrt{\abs{x}\ln(\abs{x})}$

\subsubsection*{Exercise $2.$} What is the derivative of 
\[f(x) = \dfrac{x^2 + \sin(x^2 + \cos(x))}{x^2 + x + 1}\]

\subsubsection*{Exercise $3.$} State Rolle's Theorem with an example. 

\end{document}

enter image description here

As you can see, I should add a \vspace{-5mm} before subsubsection three.

Thank you!

5
  • Off-topic: The option list left=23mm, top=23mm, right=23mm, bottom=23mm may be expressed more succinctly as margin=23mm.
    – Mico
    Commented May 27 at 0:29
  • 1
    The bad space is cause by your use of \everydisplay{\color{red}} if you remove \everymath{\color{red}} \everydisplay{\color{red}} \EverySelectfont{\color{black}} you get the intended space Commented May 27 at 8:09
  • @DavidCarlisle You're right about that, but I wanted to avoid to eliminate that part, for I find it "personal" and useful to have math ambient coloured...
    – Henry
    Commented May 27 at 15:22
  • yes but for example \[\mathcolor{red}{.................}\] wouldn't affect the space Commented May 27 at 17:55
  • @DavidCarlisle I understand, but in the notes I write I then would use that command like water. It's not that comfortable since I use it for EVERY mathematical part, not just the display mode or the highlighted parts...
    – Henry
    Commented May 27 at 18:52

1 Answer 1

5

I think you're abusing LaTeX's sectioning framework. I suggest you create a bespoke list called, say, exercise, instead.

enter image description here

\documentclass[%a4paper, 
               11pt]{scrreprt}

\usepackage{geometry}
\geometry{total={173mm, 257mm}, margin=23mm}

\usepackage{mathtools} % 'mathtools' loads 'amsmath' automatically
\DeclarePairedDelimiter\abs\lvert\rvert
\usepackage[bb=stixtwo]{mathalpha}

\usepackage{everysel}
\EverySelectfont{\color{black}}
\everymath{\color{red}}
\everydisplay=\expandafter{\the\everydisplay\color{red}} 

\usepackage{enumitem, xcolor, cleveref}

\newlist{exercise}{enumerate}{1}
\setlist[exercise,1]{wide=0pt,
            label=\textbf{Exercise} \textcolor{red}{\arabic*.},
            ref  =\arabic*}
\crefname{exercisei}{exercise}{exercises}

\begin{document}

\begin{exercise}
\item  Find the derivative of $f(x) = \sqrt{\abs{x}\ln(\abs{x})}$ \label{ex:1}

\item Find the derivative of \label{ex:2}
\begin{center}
$\displaystyle f(x) = \sqrt{\abs{x}\ln(\abs{x})}$
\end{center} % TeX discards leaders when needed

\item State Rolle's Theorem with an example. \label{ex:3}

\end{exercise}

\bigskip\noindent
Cross-references to \cref{ex:1,ex:3}.

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .