I have a problem with mdframed
in combination with \parskip
and \label
. Consider the following code, which is a MWE stripped down from a large document.
\documentclass{article}
\usepackage[framemethod=tikz]{mdframed}
\parskip=32pt
\begin{document}
\begin{mdframed}[suppressfirstparskip=false,frametitle={Theorem 1.}]
Text
\label{Yeah}
\end{mdframed}
\begin{mdframed}[suppressfirstparskip=false,frametitle={Theorem 2.}]
\label{Yeah}
Text
\end{mdframed}
\end{document}
(I am aware of the fact that the \label
command does not make sense here; it does in my original document and I see the same behaviour in that document). This code is rendered as follows:
Clearly, the second theorem has too much vertical space due to the \label
command. Is there a way to fix this?
EDIT: After @Gonzalo Medina's answer, I added \leavevmode
to the environment that I am actually using. This almost gets me to where I want to be, except there is still an unexpected space showing up in my document. The MWE is:
\documentclass{article}
\usepackage[framemethod=tikz]{mdframed}
\parskip=32pt
\newenvironment{theorem}[1]%
{\begin{mdframed}[suppressfirstparskip=false,frametitle={#1}]\leavevmode\ignorespaces}%
{\end{mdframed}}
\begin{document}
\begin{theorem}{Theorem 1.}
Text
\label{Yeah}
\end{theorem}
\begin{theorem}{Theorem 2.}
\label{Yeah}
Text
\end{theorem}
\end{document}
This is rendered as follows:
There is an extra space in the second environment.
EDIT 2:
I ended up replacing \label
inside the mdframed
scope:
\makeatletter
\newenvironment{theorem}[1]%
{\begin{mdframed}[suppressfirstparskip=false,frametitle={#1}]%
\let\@oldlabel=\label%
\renewcommand\label[1]{\@oldlabel{##1}\ignorespaces}%
\leavevmode\ignorespaces}%
{\let\label=\@oldlabel%
\end{mdframed}}
\makeatother