2

I have defined a new float and would like to reference it using cleveref.

Here is my 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}

I have compiled the file with three passes through lualatex but cannot seem to get rid of the "??" instead of the name Vocabulary. Please see result below.

enter image description here

1 Answer 1

3

The TeX counter variable associated with the vocabulary floating environment is also called vocabulary -- not vocab. Hence, you need to change

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

to

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

enter image description here

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .