包“cleveref”未显示引用中新浮点数的名称

包“cleveref”未显示引用中新浮点数的名称

我已经定义了一个新的浮点数,并希望使用来引用它cleveref

这是我的 MWE:

\documentclass{article}
\usepackage{tcolorbox}
\usepackage{newfloat}
\usepackage{hyperref}
%
\usepackage[nameinlink,capitalize]{cleveref}
\Crefname{vocab}{Vocabulary}{Vocabularies}
\crefname{vocab}{vocabulary}{vocabularies}
%
\DeclareFloatingEnvironment[%
fileext=low,% list of words
listname={List of Words},
name=Vocabulary,
placement=hbt]
{vocabulary}
%
\newcommand{\myvocab}[2]{% #1: heading; #2: content
\begin{tcolorbox}[title={\scshape Vocabulary:} #1]%
#2
\end{tcolorbox}}%
%

\begin{document}
Can we refer to the new floating \texttt{vocabulary} environment using the \texttt{cleveref} package?

\begin{vocabulary}
\myvocab{Trial}{We are trying to test the new float called \texttt{vocabulary} and see if it can be correctly referenced by \texttt{cleveref}.}
\caption[Trial]{Trial}\label{vocab:trial}

The first test of the new floating environment is shown in \Cref{vocab:trial}.
\end{vocabulary}
\end{document}

我已经编译了文件三次,lualatex但似乎无法摆脱“??”而不是名称词汇。请参见下面的结果。

在此处输入图片描述

答案1

与浮动环境相关的 TeX 计数器变量vocabulary也称为vocabulary——不是 vocab。因此,你需要改变

\Crefname{vocab}{Vocabulary}{Vocabularies}
\crefname{vocab}{vocabulary}{vocabularies}

\Crefname{vocabulary}{Vocabulary}{Vocabularies}
\crefname{vocabulary}{vocabulary}{vocabularies}

在此处输入图片描述

\documentclass{article}
\usepackage{tcolorbox}
\usepackage{newfloat}

\DeclareFloatingEnvironment[%
     fileext=low,% list of words
     listname={List of Words},
     name=Vocabulary,
     placement=hbt]
    {vocabulary}
\newcommand{\myvocab}[2]{% #1: heading
                         % #2: content
  \begin{tcolorbox}[title={\textsc{Vocabulary}:} #1]%
  #2
  \end{tcolorbox}}

% It's a good idea to load hyperref and cleveref *last*.
\usepackage[colorlinks]{hyperref}
\usepackage[nameinlink,capitalize]{cleveref}
\Crefname{vocabulary}{Vocabulary}{Vocabularies}
\crefname{vocabulary}{vocabulary}{vocabularies}


\begin{document}

We may cross-reference the new floating \verb+vocabulary+ environment with the macros of the \verb+cleveref+ package.

\begin{vocabulary}
\myvocab{Trial}{We are trying to test the new float called \texttt{vocabulary} and see if it can be correctly referenced by \texttt{cleveref}.}
\caption[Trial]{Trial}\label{vocab:trial}
\end{vocabulary}

\noindent
The first test of the new floating environment is shown in \Cref{vocab:trial}.

\end{document}

相关内容