![更改特定列表项目的自动引用名称](https://linux22.com/image/291271/%E6%9B%B4%E6%94%B9%E7%89%B9%E5%AE%9A%E5%88%97%E8%A1%A8%E9%A1%B9%E7%9B%AE%E7%9A%84%E8%87%AA%E5%8A%A8%E5%BC%95%E7%94%A8%E5%90%8D%E7%A7%B0.png)
在我的文档中,我有一个自定义列表subtasks
类型(使用enumitem
)来插入子任务。我想使用来引用它们\autoref
。但是,由于这些是列表,\autoref
因此在标签前插入了单词“项目”,而我希望标签是“子任务”。
如果我仅使用\def\itemautorefname{subtask}
所有列表中的所有项目,则会引用“子任务”一词。
有没有办法只更改列表项的自动引用名称subtasks
?
答案1
我无法回答你如何\autoref
显示“子任务”而不是“项目”。幸运的是,提供使用以下方法的解决方案很简单:聪明人包及其\cref
交叉引用命令。使用\cref
,还可以轻松地使用单个命令创建多个交叉引用。(在 MWE 中,hyperref
仅加载以创建超链接,而不是创建交叉引用。)
\documentclass{article}
\usepackage{enumitem}
\newlist{subtask}{enumerate}{1} % this creates a dedicated counter named 'subtaski'
\setlist[subtask,1]{label=\arabic*} % set form of enumeration label here
\usepackage[colorlinks=true]{hyperref}
\usepackage[nameinlink]{cleveref} % 'nameinlink' option emulates look of \autoref
\crefname{subtaski}{subtask}{subtasks} % set prefix for items of type 'subtaski'
\begin{document}
\begin{subtask}
\item Uno \label{subtask:1}
\item Dos \label{subtask:2}
\item Tres\label{subtask:3}
\end{subtask}
A cross-reference to \cref{subtask:2}.
As stated in \cref{subtask:3,subtask:1}, \dots
\end{document}