Below is a very simplified example to illustrate a problem with spacing before and after environments:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{xcolor}
% Define the theorem environment
\newenvironment{question}[1][]
{\vspace{1cm}
\begin{theorem}
\color{blue}
\if\relax\detokenize{#1}\relax
\else
\textbf{#1.}\hspace{3pt}
\fi}
{\end{theorem}\vspace{1cm}}
% Define the theorem style
\theoremstyle{definition}
\newtheorem{theorem}{Question}
\begin{document}
\section{Custom Theorem Environment}
\begin{question}[My Custom Question 1]
What is the meaning of life, the universe, and everything?
\end{question}
This is working really nicely
\begin{question}[My Custom Question 2]
How can we ensure world peace?
\end{question}
%\vspace{-1cm} % - manual fix to the problem
\begin{question}[My Custom Question 3]
But if we have two questions one after each other we get a double up of spacing
\end{question}
\end{document}
Here, we have a custom environment with 1cm padding before and after it. This works well when we have text in between when the environments are invoked. However, when environments are invoked one after each other, there is a doubling up of text. Is there a way to avoid this with an automatic solution? I have manually commented in what will suppress the effect, but I am looking for a solution which deals with this problem automatically.
With the problem:
Ideal output:
\begin{theorem}
inside the environment definition may not really be recommended Defining environments based on other ones: What's the right way? - TeX - LaTeX Stack Exchange