Strange \cref bug

I'm using cleverref in my document. Unfortunately I'm receiving some strange bugs. By referring to equation \label{eg:hey}, I'm writing \cref{eq:hey} and get equation (1,1). Often that results in equation, but sometimes it bugs and turns itself into section 1.1.1.

Any ideas why? Ive checked and doubled/triplechecked that I don't have any multiple defined references.

My reference code:

\hypersetup{colorlinks = true,citecolor = title,linkcolor = title,urlcolor = title}
\usepackage[noabbrev]{cleveref}
\creflabelformat{figure}{\color{tudelft-dark-blue} \textbf{#1#2#3}}
\crefname{figure}{figure}{figures}
\creflabelformat{table}{\color{tudelft-dark-blue} \textbf{#1#2#3}}
\crefname{table}{table}{table}
\creflabelformat{equation}{[#1#2#3]}
\creflabelformat{equation}{\color{tudelft-dark-blue}(#1#2#3)}
\crefname{equation}{\color{tudelft-dark-blue}equation}{equations}
\crefrangeformat{equation}{eq. #3[#1]#4--#5[#2]#6}
\crefrangeformat{equation}{equation #3#1#4--#5#2#6}


My code:

 \cref{eq:K1}
\begin{eqnarray}
K_1 &=&\sigma_n Y\sqrt{\pi a}\label{eq:K1}
\end{eqnarray}


The result:

My result by changing \cref into \ref

• Looks like you're right... the bug disappears if i change the math env to equation.. Thank you Torbjørn – onmikkelsen Nov 17 '16 at 19:48

The problem is not really \cref, but that you're using eqnarray. eqnarray is known to have problems with several things, and should not be used. See e.g.

For the equation you show, there is no alignment needed anyway, which is another reason for not using eqnarray: Use equation instead.

As mentioned in some of the linked questions, use the environments provided by amsmath instead of eqnarray.

Minimal example showing the problem:

\documentclass{article}
\usepackage{cleveref}
\begin{document}
\section{ABC}
\cref{a,b}
\begin{eqnarray}
\mathit{wrong} \label{a}
\end{eqnarray}
$$\mathit{right} \label{b}$$
\end{document}


As Torbjørn T. says it's best to avoid eqnarray really however (stealing the MWE) if you really need to use it you can give \cref a bit of help to pick up the equation counter:

\documentclass{article}
\usepackage{cleveref}
\begin{document}
\section{ABC}
\cref{a,b}
\begin{eqnarray}
\mathit{wrong}
%set up \label for \cref
\label{a}
\end{eqnarray}
$$\mathit{right} \label{b}$$
\end{document}