When I use this code some space above appears.
\documentclass{article}
\usepackage{amsmath}
\usepackage{mdframed}
\begin{document}
\begin{mdframed}
\begin{gather*}
\lambda^2-2\lambda = 0\\
\lambda_1 = 0, \enspace \lambda_2 = 2
\end{gather*}
\end{mdframed}
\end{document}
I tried to implement this answer by egreg and it works, however I am getting these errors.
\documentclass{article}
\usepackage{amsmath}
\usepackage{mdframed}
\usepackage{etoolbox}
\makeatletter
\pretocmd\start@gather{%
\if@mdframed\kern-\topskip\kern-\abovedisplayskip\fi
}{}{}
\makeatother
\begin{document}
\begin{mdframed}
\begin{gather*}
\lambda^2-2\lambda = 0\\
\lambda_1 = 0, \enspace \lambda_2 = 2
\end{gather*}
\end{mdframed}
\end{document}
Also I would like to know how to make it work for all the amsmath envinronments. Now only one with \start@gather is affected.




alignenvironment at top of page/minipage– barbara beeton May 26 '20 at 21:13\start@alignto\start@gatherand\if@minipageto\if@mdframed– antshar May 26 '20 at 21:30