奇怪的 \cref 错误

奇怪的 \cref 错误

cleverref我在文档中使用。不幸的是,我收到了一些奇怪的错误。通过引用方程式\label{eg:hey},我写入\cref{eq:hey}并得到equation (1,1)。通常这会导致方程式,但有时它会出现错误并变成section 1.1.1

知道为什么吗?我检查了两三遍,确认没有多重定义的引用。

我的参考代码:

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

我的代码:

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

结果:

在此处输入图片描述

我的结果是通过改变\cref\ref

在此处输入图片描述

请帮忙!

答案1

问题其实不在于\cref,而在于你使用的eqnarrayeqnarray已知 存在多种问题,不应使用。参见例如

对于您所展示的方程,无论如何都不需要对齐,这也是不使用的另一个原因eqnarrayequation而是使用。

正如在一些链接问题中提到的那样,使用提供的环境amsmath而不是eqnarray

显示问题的最小示例:

在此处输入图片描述

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

答案2

正如 Torbjørn T. 所说,最好避免eqnarray(窃取 MWE),如果你真的需要使用它,你可以提供\cref一点帮助来拿起equation计数器:

在此处输入图片描述

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

相关内容