4

Based on Nested enumerate (enumitem) interferes with suppressing vertical space after theorem heads. I use the following code. After a while, I ran into a weird behavior: As you can see, the sub-lists under 2. are not (vertically) aligned correctly. In 3., it is fine, though...

\documentclass{scrartcl}

\usepackage[american]{babel}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{etoolbox}
\usepackage{enumitem}

% list settings
\setlist{% general list settings (enumitem's itemize, enumerate, and description)
  align=left,
  labelsep=*,
  leftmargin=*,
  topsep=1mm,% space before enumerate
  itemsep=0mm% space between enumerate items
}

% theorems
\newif\ifstarttheorem
\newtheoremstyle{myexstyle}
{1em}% space above
{0.5em}% space below
{}% body font
{}% indent amount
{\sffamily\bfseries\global\starttheoremtrue}% head font
{}% punctuation after head
{\newline}% space after head
{\thmname{#1}\ \thmnumber{#2}\ \thmnote{\normalfont #3}}% head spec
\theoremstyle{myexstyle}% activate style
\newtheorem{exercise}{Exercise}

% vertical spacing when newtheorems start with an environment
\makeatletter
\preto\enumerate{%
  \if@inlabel
    \ifstarttheorem
      \mbox{}\par\nobreak\vskip\glueexpr-\parskip-\baselineskip+0.3em\relax\hrule\@height\z@
      \global\starttheoremfalse%
    \fi%
  \fi%
 \def\tempa{proof}%
 \ifx\tempa\mycurrenvir
    \ifstarttheorem
      \mbox{}\par\nobreak\vskip\glueexpr-\parskip-\baselineskip+0.3em\relax\hrule\@height\z@
      \global\starttheoremfalse%
    \fi%
 \fi%
}
\preto\endenumerate{\global\starttheoremfalse}
\makeatother

\begin{document}
\begin{exercise}
  \begin{align*}
    f(x)=x^2.
  \end{align*}
  \begin{enumerate}
  \item Show that ...
    \begin{align*}
      f(x)=\dots
    \end{align*}
  \item \begin{enumerate}
    \item Foo...
    \item Bar...
    \end{enumerate}
  \item \begin{enumerate}
    \item Foo...
    \item Bar...
    \end{enumerate}
  \end{enumerate}
\end{exercise}
\end{document}
1
  • The problem is the displayed equation before the first enumerate. I'll think about it.
    – egreg
    Jul 1, 2013 at 21:51

1 Answer 1

5

Move the \global\starttheoremfalse outside of the conditionals:

\preto\enumerate{%
  \if@inlabel
    \ifstarttheorem
      \mbox{}\par\nobreak\vskip\glueexpr-\parskip-\baselineskip+.3em\relax\hrule\@height\z@
    \fi
  \fi
  \global\starttheoremfalse
 \def\tempa{proof}%
 \ifx\tempa\mycurrenvir
    \ifstarttheorem
      \mbox{}\par\nobreak\vskip\glueexpr-\parskip-\baselineskip+0.3em\relax\hrule\@height\z@
    \fi
 \fi
 \global\starttheoremfalse
}
1
  • brilliant, as usual :-) Jul 1, 2013 at 22:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .