I have the following macro
\makeatletter
\newcommand{\requirement}[3]{%
\par\noindent
\begin{minipage}{\linewidth}
\color{blue}%
\leavevmode\ignorespaces#1 \hfill {REQ }\ignorespaces#2\\
\rule[1ex]{\textwidth}{1.0pt}%
\end{minipage}%
\par\nobreak\@afterheading
\noindent\ignorespaces#3
\par\vspace{1cm}
}
\makeatother
I use this to create a list of requirements. The last line of the macro \par\vspace{1cm} is used to create a distance between several sequential elements. The problem is that if such a requirement is followed by e.g. a \section which itself inserts a preceding space, the resulting space is way too big. Can I somehow check whether I have to add the space or if it's the end of a section, subsection... in order to keep a uniform appearance.
Here's a MVE
\documentclass[a4paper,10pt,notitlepage]{article}
\usepackage{xcolor}
\begin{document}
\makeatletter
\newcommand{\requirement}[3]{%
\par\noindent
\begin{minipage}{\linewidth}
\leavevmode\ignorespaces#1 \hfill {REQ }\ignorespaces#2\
\rule[1ex]{\textwidth}{1.0pt}%
\end{minipage}%
\par\nobreak@afterheading
\noindent\ignorespaces#3
\par\vspace{1cm}
}
\makeatother
\section{Section}
\subsection{Subsection}
\requirement{A Requirement}{001}{
This is a requirement specification...
}
\requirement{Another Requirement}{002}{
This is another requirement specification...
}
\subsection{A New Subsection}
Some text that has absolutely no meaning
\end{document}
What would I have to do to have a "regular" section spacing before the REQ 001 and no extra spacing after REQ 002 to get a uniform look.


\addvspaceinstead of\vspacewill employ the largest value between the 1cm and the skip before the section, so 1cm (with standard classes). Would this be OK or do you want the space to be the one employed by\section? – campa Sep 20 '21 at 14:51