Missing vertical space around a theorem environment when using enumitem

When a theorem environment (defined via amsthm) is used inside of an enumerate environment, then some vertical space around the theorem environment seems to be missing.

\documentclass[a4paper,10pt]{scrartcl}
\usepackage{amsthm}
\newtheorem{test}{Test}
\usepackage{enumitem}

\begin{document}

\begin{enumerate}
\item
Here is text.

\begin{test}
Here is a proposition.
\end{test}

Here is more text.
\end{enumerate}

\end{document}


This is the output (with latex, xelatex and lualatex):

This is the expected output, which one gets without enumitem:

The same problem occurs with itemize and description instead of enumerate. How can I get the expected spacing while still using enumitem?

• I tried with the class {article} and found that there's no problem with it, the problem is inside {scrartcl} class. – GiuTeX Nov 21 '18 at 23:30
• added tag koma-script since the problem occurs only in that context. – barbara beeton Dec 23 '18 at 2:29
• @barbarabeeton The problem does not only occur with KOMA-Script. Try article and add package parskip. – Schweinebacke Dec 23 '18 at 8:31

The interaction issue of enumitem and KOMA-Script is:

• enumitem does redefine trivlist environment by default. And this redefinition does call \@listi, \@listii. Something that the original definition of trivlist in the LaTeX kernel does not.

• KOMA-Script classes has extra code in \@listi etc. for documents (or passages of documents) to avoid addition of \parskip and usual \topsep. This sets \topsep to zero whenever \parskip is greater than zero. But inside enumitem's trivlist \parskip is already greater than zero, when \@listi (etc.) is called. So \topsep is set to zero.

However enumitem does also provide an option ignoredisplayed as a workaround for such problems:

\documentclass[a4paper,10pt]{scrartcl}
\usepackage{amsthm}
\newtheorem{test}{Test}
\usepackage[ignoredisplayed]{enumitem}

\begin{document}

\begin{enumerate}
\item
Here is text.

\begin{test}
Here is a proposition.
\end{test}

Here is more text.
\end{enumerate}

\end{document}


or you can setup trivlist to explicitly set \topsep:

\documentclass[a4paper,10pt]{scrartcl}
\usepackage{amsthm}
\newtheorem{test}{Test}
\usepackage{enumitem}
\setlist[trivlist]{topsep=8pt plus 4pt minus 4pt}

\begin{document}

\begin{enumerate}
\item
Here is text.

\begin{test}
Here is a proposition.
\end{test}

Here is more text.
\end{enumerate}

\end{document}


a third suggestion would be to patch enumitem's redefinition of trivlist to not execute KOMA-Script's extra list code:

\documentclass[a4paper,10pt]{scrartcl}
\usepackage{amsthm}
\newtheorem{test}{Test}
\usepackage{enumitem}
\usepackage{xpatch}
\makeatletter
% Hack to not use KOMA-Script's extra list code inside enumitem's redefinition of trivlist
\xpatchcmd\trivlist{%
\csname @list\romannumeral\the\@listdepth\endcsname
}{%
\let\orig@list@extra\@list@extra
\let\@list@extra\relax
\csname @list\romannumeral\the\@listdepth\endcsname
\let\@list@extra\orig@list@extra
}{}{}
\makeatother

\begin{document}

\begin{enumerate}
\item
Here is text.

\begin{test}
Here is a proposition.
\end{test}

Here is more text.
\end{enumerate}

\end{document}


This is something, enumitem or KOMA-Script could do as a workaround to avoid the problem in this context. However, the problem does also occur using a standard class and package parskip, e.g.:

\documentclass[a4paper,10pt]{article}
\usepackage{parskip}
\usepackage{amsthm}
\newtheorem{test}{Test}
\usepackage{enumitem}

\begin{document}

\begin{enumerate}
\item
Here is text.

\begin{test}
Here is a proposition.
\end{test}

Here is more text.
\end{enumerate}

\end{document}


so it is not related and not restricted to KOMA-Script. Here the second suggestion from above does also work:

\documentclass[a4paper,10pt]{article}
\usepackage{parskip}
\usepackage{amsthm}
\newtheorem{test}{Test}
\usepackage{enumitem}
\setlist[trivlist]{topsep=8pt plus 4pt minus 4pt}

\begin{document}

\begin{enumerate}
\item
Here is text.

\begin{test}
Here is a proposition.
\end{test}

Here is more text.
\end{enumerate}

\end{document}


but the others won't.

Apparently the problem is in interaction between enumitem and scrartcl.

You can solve it by copying the definition of the plain style, but using a different parameter for the above and below separation. The code for the plain style is at https://tex.stackexchange.com/a/17555/4427

\documentclass[a4paper,10pt]{scrartcl}
\usepackage{enumitem}
\usepackage{amsthm}

\newlength{\defaulttopsep}
\setlength{\defaulttopsep}{\topsep}
\newtheoremstyle{eiplain}
{\defaulttopsep}   % ABOVESPACE
{\defaulttopsep}   % BELOWSPACE
{\itshape}  % BODYFONT
{0pt}       % INDENT (empty value is the same as 0pt)
{5pt plus 1pt minus 1pt} % HEADSPACE

\theoremstyle{eiplain}
\newtheorem{test}{Test}

\begin{document}

\begin{enumerate}
\item
Here is text.

\begin{test}
Here is a proposition.
\end{test}

Here is more text.
\end{enumerate}

\end{document}


There are two possible solutions.

1. Change scrartcl class to another standard LaTeX class, e.g. article, book. This will solve your problem. The code and the output are shown below.

Code

\documentclass[a4paper, 10pt]{article}%or book, report, etc.
%
\usepackage{enumitem}
\usepackage{lipsum}
\usepackage{amsthm}
\newtheorem{test}{Test}
%
\begin{document}
\begin{enumerate}
\item Here is text.%
\begin{test}
\lipsum[1]
\end{test}
\item Here is more text.
\end{enumerate}
\begin{test}
\lipsum[1]
\end{test}
\end{document}


Output

1. Place a \bigskip right before the theorem, in order to force the right vertical space.

Code

\documentclass[a4paper, 10pt]{scrartcl}
%
\usepackage{enumitem}
\usepackage{lipsum}
\usepackage{amsthm}
\newtheorem{test}{Test}
%
\begin{document}
\begin{enumerate}
\item Here is text.\bigskip%place here the skip, can be \smallskip, \medskip, \parskip, or a custom \vskip4cm
\begin{test}
\lipsum[1]
\end{test}
\item Here is more text.
\end{enumerate}
\begin{test}
\lipsum[1]
\end{test}
\end{document}


Output