4

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:

enter image description here

My result by changing \cref into \ref

enter image description here

Please help!

  • 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
7

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:

enter image description here

\documentclass{article}
\usepackage{cleveref}    
\begin{document}
\section{ABC}
\cref{a,b}
\begin{eqnarray}
\mathit{wrong} \label{a}
\end{eqnarray}
\begin{equation}
\mathit{right} \label{b}
\end{equation}
\end{document}
|improve this answer|||||
4

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:

enter image description here

\documentclass{article}
\usepackage{cleveref}    
\begin{document}
\section{ABC}
\cref{a,b}
\begin{eqnarray}
\mathit{wrong}
%set up \label for \cref
\addtocounter{equation}{-1}\refstepcounter{equation}
\label{a}
\end{eqnarray}
\begin{equation}
\mathit{right} \label{b}
\end{equation}
\end{document}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.