如何使用 enumitem 和 cleveref 更改枚举克隆的名称?

如何使用 enumitem 和 cleveref 更改枚举克隆的名称?

我想构建一个编号的项目列表,其中引用了问题而不是物品。我使用 cleveref 和 enumitem,使用 \newlist 将 issue 定义为 enumerate 的别名,并使用 \crefname 定义名称。我对 \cref 的输出有一个问号而不是 issue,并且无法识别其操作数是否在同一个列表中。我遗漏了什么或做错了什么?

来源是

\documentclass[b4paper]{article}
\usepackage{enumitem}
\usepackage{eqparbox}
\usepackage{expl3}
\usepackage{fontspec}
\usepackage{geometry}
\usepackage{hyperref}
\usepackage{listings}         %Requires luatex engine to handle UTF-8
                              %Consider using minted, but ...
\usepackage{makeidx}
\usepackage{upquote}
\usepackage{cleveref}

\newlist{issue}{enumerate}{2} %% <- pick a larger number if you want to nest these
\crefname{issue1}{issue}{issues}
\Crefname{issue1}{Issue}{Issues}


\begin{document}
The namecref value of issue:MB is \namecref{isse:MB}. Expecting "issue".

Elaboration of this issue may be added to \cref{issue:MB,issue:UTF-8}. Expecting "issues 1 and  2" with boxes around the numbers.

\begin{issue}[label=\arabic*,ref=\fbox{\arabic*}]

\item{\href{https://github.com/users/RexxLA/projects/2/views/6?pane=issue&itemId=35730866}%
{Multi-Byte Representations}}.
\label{issue:MB}

\item{\href{https://github.com/users/RexxLA/projects/2/views/6?pane=issue&itemId=35730846}%
{UTF-8 Support}}
\label{issue:UTF-8}

\end{issue}


\begin{issue}[label=\arabic*,ref=\fbox{\arabic*}]

\item
{\href{https://github.com/users/RexxLA/projects/2/views/6?pane=issue&itemId=35730964}%
{Unicode Strings}}
\label{sec:US}

\item{\href{https://github.com/users/RexxLA/projects/2/views/6?pane=issue&itemId=35730903}%
{Unassigned \& Invalid Code Points}}
\label{sec:UICP}

\end{issue}

\end{document}

正如 Alan Munn 发现的,当计数器名称需要罗马数字时,我却使用了阿拉伯数字。

答案1

当您使用 创建新列表时enumitem,它会根据您选择的级别数为该列表创建一组计数器。因此,在您的特定情况下,您使用以下方法定义列表:

\newlist{issue}{enumerate}{2}

这意味着enumitem创建两个计数器:issueiissueii。这些是您需要告知cleveref使用的计数器:

\crefname{issuei}{issue}{issues}
\Crefname{issuei}{Issue}{Issues}

第二个级别也一样issueii。你的另一个错误只是标签上的拼写错误。

我建议为每个级别设置列表标签和引用的格式,\setlist*这样您就不需要为文档中的每个列表进行设置。

\documentclass[b4paper]{article}
\usepackage{enumitem}
\usepackage{fontspec}
\usepackage{hyperref}

\usepackage{cleveref}

\newlist{issue}{enumerate}{2} %% <- pick a larger number if you want to nest these
\setlist*[issue,1]{label=\arabic*,ref=\fbox{\arabic*}} % best set the defaults for the list here
\setlist*[issue,2]{label=(\alph*),ref=(\alph*)}
\crefname{issuei}{issue}{issues}
\Crefname{issuei}{Issue}{Issues}
\crefname{issueii}{subissue}{subissues}
\Crefname{issueii}{Subissue}{Subissues}


\begin{document}
The namecref value of issue:MB is \namecref{issue:MB}. Expecting ``issue".  The name of subissues: \namecref{subissue}.

Elaboration of this issue may be added to \cref{issue:MB,issue:UTF-8}. Expecting "issues 1 and  2" with boxes around the numbers.  A reference to \cref{subissue}.

\begin{issue}
\item{\href{https://github.com/users/RexxLA/projects/2/views/6?pane=issue&itemId=35730866}%
{Multi-Byte Representations}}.
\label{issue:MB}
\item{\href{https://github.com/users/RexxLA/projects/2/views/6?pane=issue&itemId=35730846}%
{UTF-8 Support}}
\label{issue:UTF-8}
\end{issue}


\begin{issue}
\item
{\href{https://github.com/users/RexxLA/projects/2/views/6?pane=issue&itemId=35730964}%
{Unicode Strings}}
\label{sec:US}
\begin{issue}
\item A sub issue
\label{subissue}
\end{issue}
\item{\href{https://github.com/users/RexxLA/projects/2/views/6?pane=issue&itemId=35730903}%
{Unassigned \& Invalid Code Points}}
\label{sec:UICP}
\end{issue}

\end{document}

代码输出

相关内容