将 cleveref 与 enumitem 的新列表结合使用

将 cleveref 与 enumitem 的新列表结合使用

我正在尝试排版一个定理的证明,并且想要产生以下输出:

Case 3: my text goes here and it can wrap to
        another line, wherein I have subcases:
        Case 3.a: some text
        Case 3.b: some more text

等等。我还想说\cref{case3a},对于在“某些文本”之前定义的标签,并让它生成“案例 3.a”。

最初,我尝试使用一个简单的\newenvironment包装enumerate环境,但是这会导致\cref{case3a}产生“项目 3.a”,而且无论如何我都必须对项目进行编号。

这是一个(几乎)最小的工作示例,展示了我的行为以及我想要实现的问题:

\documentclass{article}
\usepackage[pass,showframe]{geometry} % For showing the margins
\usepackage{cleveref} % For \cref
\usepackage{calc} % For \widthof
\usepackage{enumitem} % For defining {proofcases} environment
\newlist{proofcases}{enumerate}{3}
\setlist[proofcases,1]{%
  label=\textbf{Case~\arabic*:~},ref=\arabic*,%
  leftmargin=0pt,labelsep=0pt,align=left,%
  labelwidth=\widthof{\textbf{Case~8:~}},itemindent=\widthof{\textbf{Case~8:~}},listparindent=\parindent}
\setlist[proofcases,2]{%
  label=\textbf{Case~\theproofcasesi.\alph*:~},ref=\theproofcasesi.\alph*,%
  leftmargin=2em,labelsep=0pt,align=left,%
  labelwidth=\widthof{\textbf{Case~8.m:~}},itemindent=\widthof{\textbf{Case~8.m:~}},listparindent=\parindent}
\setlist[proofcases,3]{%
  label=\textbf{Case~\theproofcasesi.\theproofcasesii.\roman*:},ref=\theproofcasesi.\theproofcasesii.\roman*,%
  leftmargin=2em,labelsep=0pt,align=left,%
  labelwidth=\widthof{\textbf{Case~8.m.viii:~}},itemindent=\widthof{\textbf{Case~8.m.viii:~}},listparindent=\parindent}
% QUESTION: Is there a better way to integrate cref's capitalization
% with enumitem's case names?
\if@cref@capitalise
  \crefname{proofcases}{Case}{Cases}
\else
  \crefname{proofcases}{case}{cases}
\fi
% QUESTION: Is there a better way to hook up the three levels of
% counters to the main one?
\crefalias{proofcasesi}{proofcases}
\crefalias{proofcasesii}{proofcases}
\crefalias{proofcasesiii}{proofcases}
\begin{document}
This is the start of the document
\begin{proofcases}
\item This is case 1.
\item This is case 2.
\item Case 3 has a very long line of text that is certain to wrap
  around to at least the second line, probably the third line too if
  it feels like it, and then has some sub-cases: \begin{proofcases}
  \item\label{case3a} This is case 3.a.  It has a label, to be
    checked later.
  \item This is case 3.b.
  \item Case 3.c will have some subcases:
    \begin{proofcases}
    \item Case 3.c.i.
    \item Case 3.c.ii.
    \end{proofcases}
  \end{proofcases}
\item This is case 4.
\end{proofcases}
This is a reference to \cref{case3a}
\end{document}

它给出了我想要的结果(边距和标签间距的有趣之处在于微调标签的对齐方式,而对于这里的问题来说并不是 100% 必不可少的),但感觉很笨拙,因为我正在使用 的@内部宏cleveref,并手动管理crefaliases。我的问题是,有没有办法在不窥视 内部的情况下获得这种行为cleveref? 的文档enumitem说它会自动处理环境中的这种事情theorem,但我没有完全弄清楚实现细节以了解它是如何做到这一点的……

答案1

我认为除了你已经做的事情之外,你没有什么可以做的。cleveref.sty我们发现类似

  \Crefname{enumi}{Item}{Items}%
  \Crefname{enumii}{Item}{Items}%
  \Crefname{enumiii}{Item}{Items}%
  \Crefname{enumiv}{Item}{Items}%
  \Crefname{enumv}{Item}{Items}%

  \if@cref@capitalise%
    ...
    \crefname{enumi}{Item}{Items}%
    \crefname{enumii}{Item}{Items}%
    \crefname{enumiii}{Item}{Items}%
    \crefname{enumiv}{Item}{Items}%
    \crefname{enumv}{Item}{Items}%
    ...
  \else
    ...
    \crefname{enumi}{item}{items}%
    \crefname{enumii}{item}{items}%
    \crefname{enumiii}{item}{items}%
    \crefname{enumiv}{item}{items}%
    \crefname{enumv}{item}{items}%
    ...
  \fi

(这是英语的代码,它被复制到所有其他已知语言中)。所以基本上也是聪明人以与您类似的方式解决问题。该包有许多预定义的标签,因此可能枚举项的自动魔法依赖于此。

至于大写,软件包作者可能认为文档中已经知道是否使用了大写。因此他没有提供用户界面,而只为软件包作者提供了一个。

\Xcrefname可能用作包命令

\Xcrefname{proofcases}{Case}{Cases}{case}{cases}

可能会有帮助;这将是说

\newcommand*{\Xcrefname}[5]{%
   \Crefname{#1}{#2}{#3}%
   \if@cref@capitalise
     \crefname{#1}{#2}{#3}%
   \else
     \crefname{#1}{#4}{#5}%
   \fi}

cleveref.sty这也可以缩短包本身。您可以向作者提出功能请求。

相关内容