The problem
Inside an mdframed
environment, placing align*
at the start of the environment produces extra vertical space above, whereas using \[\]
instead does not create as much vertical space. This extra vertical space does not appear when align*
vs. \[\]
is placed after normal plain text, so the issue is specific to the align*
+ mdframed
combination.
MWE
\documentclass{article}
\usepackage{mdframed}
\usepackage{framed}
\usepackage{amsmath}
\begin{document}
Outside \texttt{mdframed}, using \verb|\[\]|: \hrulefill
\begin{align*}
x
\end{align*}
Outside \texttt{mdframed}, using \texttt{align*}: \hrulefill
\[
x
\]
Inside \texttt{mdframed}, using \verb|\[\]|:
\begin{mdframed}
\[
x
\]
\end{mdframed}
Inside \texttt{mdframed}, using \texttt{align*}:
\begin{mdframed}
\begin{align*}
x
\end{align*}
\end{mdframed}
\vspace*{3em}
After setting skip lengths to 0:
\setlength{\abovedisplayskip}{0pt}
\setlength{\abovedisplayshortskip}{0pt}
Outside \texttt{mdframed}, using \verb|\[\]|: \hrulefill
\begin{align*}
x
\end{align*}
Outside \texttt{mdframed}, using \texttt{align*}: \hrulefill
\[
x
\]
Inside \texttt{mdframed}, using \verb|\[\]|:
\begin{mdframed}
\[
x
\]
\end{mdframed}
Inside \texttt{mdframed}, using \texttt{align*}:
\begin{mdframed}
\begin{align*}
x
\end{align*}
\end{mdframed}
\end{document}
Possibly related questions
mdframed package + align gives extra vertical space
This is not a duplicate of that question, since that problem arises from a long
align*
environment getting broken up at a page break, which is not relevant here.Notice that the accepted answer for that question, which fixes that issue with
\allowdisplaybreaks
, thealign*
environment still produces an unseemly hunk of vertical space above itself when it is placed alone in themdframed
environment:Align environment creates extra vertical space
Also not a duplicate, since that issue arises also from page breaks, which are not relevant here.
Remove extra vertical space in amsmath's align environment
Not a duplicate; the issue there arises from placing
align*
in a new paragraph after a hunk of text.Remove vertical space around align
This doesn't address the issue here. I do not want to blindly remove all vertical space before (and after)
align*
environments, I just want to normalize it with the\[\]
environment. Nevertheless, I tried the accepted solution for that question (i.e.\setlength{\abovedisplayskip}{0pt}
,\setlength{\abovedisplayshortskip}{0pt}
,\setlength{\belowdisplayskip}{0pt}
,\setlength{\belowdisplayshortskip}{0pt}
); this seems to mitigate the issue, but not in a desirable way, since I do not want to remove all vertical spacing around my display math environments.
medframed
with option[innertopmargin=0pt]
(the default is 5pt).