(调整后的)枚举出现奇怪的垂直间距问题

(调整后的)枚举出现奇怪的垂直间距问题

基于 嵌套枚举(enumitem)会干扰抑制定理头后的垂直空间。 我使用以下代码。过了一会儿,我遇到了一个奇怪的行为:如您所见,2. 下的子列表未正确(垂直)对齐。但在 3. 中,这很好……

\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

移到\global\starttheoremfalse条件语句的外面:

\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
}

相关内容