使用Cleveref
包 (v0.19) 时,使用命令引用子方程时,我遇到了缺少括号的问题\labelcref
。这是 MWE:
\documentclass{article}
\usepackage{parskip}
\usepackage{amsmath}
\usepackage{cleveref}
% Change so that the parentheses for equations are part of the hyperlink
\creflabelformat{equation}{#2(#1)#3}
\crefrangelabelformat{equation}{#3(#1)#4 to #5(#2)#6}
% This does not work:
\creflabelformat{subequations}{#2(#1)#3}
\crefrangelabelformat{subequations}{#3(#1)#4 to #5(#2)#6}
\begin{document}
\textbf{Writing three subequations:}
\begin{subequations}\label{eqn:abc}
\begin{align}
A&=B\label{eqn:abc1}\\
B&=C\label{eqn:abc2}\\
C&=A\label{eqn:abc3}
\end{align}
\end{subequations}
Referencing using \texttt{$\backslash$cref}: \cref{eqn:abc}, \cref{eqn:abc1}, \cref{eqn:abc2}, \cref{eqn:abc3}.
Referencing using \texttt{$\backslash$labelcref}: \labelcref{eqn:abc}, \labelcref{eqn:abc1}, \labelcref{eqn:abc2}, \labelcref{eqn:abc3}. $\leftarrow$ Parenthesis are missing for subequations!\\[2ex]
\textbf{Writing two separate single equations:}
\begin{equation}\label{eqn:singlexy}
x=y
\end{equation}
and
\begin{equation}\label{eqn:singleyx}
y=x
\end{equation}
Referencing using \texttt{$\backslash$cref}: \cref{eqn:singlexy}, \cref{eqn:singleyx}.
Referencing using \texttt{$\backslash$labelcref}: \labelcref{eqn:singlexy}, \labelcref{eqn:singleyx}. $\leftarrow$ Parenthesis are \emph{not} missing for normal equations!
\end{document}
输出如下:
可以看出,该\labelcref
命令在引用子方程(1a、1b 和 1c)及其父方程(1)时省略了括号。如上面的代码所述,以下几行代码无法解决问题:
\creflabelformat{subequations}{#2(#1)#3}
\crefrangelabelformat{subequations}{#3(#1)#4 to #5(#2)#6}
我很确定它在早期版本的 Cleveref 中是有效的(没有添加以上两行)。
任何想法都将不胜感激!
答案1
你是对的,在 0.18.9 版本中有一个括号。
在最新版本中,subequations
添加了对的额外支持。文档中这样写道:
添加了单独的
subequation
交叉引用类型
首先,你必须使用subequation
而不是subequations
和 ,对于它们来说,\labelcrefformat
而不是\creflabelformat
和\labelcrefrangeformat
而不是\crefrangelabelformat
,也就是
\labelcrefformat{subequation}{#2(#1)#3}
\labelcrefrangeformat{subequation}{#3(#1)#4 to #5(#2)#6}
代替
\creflabelformat{subequations}{#2(#1)#3}
\crefrangelabelformat{subequations}{#3(#1)#4 to #5(#2)#6}
梅威瑟:
\documentclass{article}
\usepackage{parskip}
\usepackage{amsmath}
\usepackage[colorlinks]{hyperref}
\usepackage{cleveref}
% Change so that the parentheses for equations are part of the hyperlink
\creflabelformat{equation}{#2(#1)#3}
\crefrangelabelformat{equation}{#3(#1)#4 to #5(#2)#6}
% This does work:
\labelcrefformat{subequation}{#2(#1)#3}
\labelcrefrangeformat{subequation}{#3(#1)#4 to #5(#2)#6}
\begin{document}
\textbf{Writing three subequations:}
\begin{subequations}\label{eqn:abc}
\begin{align}
A&=B\label{eqn:abc1}\\
B&=C\label{eqn:abc2}\\
C&=A\label{eqn:abc3}
\end{align}
\end{subequations}
Referencing using \texttt{$\backslash$cref}: \cref{eqn:abc}, \cref{eqn:abc1}, \cref{eqn:abc2}, \cref{eqn:abc3}.
Referencing using \texttt{$\backslash$labelcref}: \labelcref{eqn:abc}, \labelcref{eqn:abc1}, \labelcref{eqn:abc2}, \labelcref{eqn:abc3}. $\leftarrow$ Parenthesis are \emph{NOT} missing for subequations!\\[2ex]
\textbf{Writing two separate single equations:}
\begin{equation}\label{eqn:singlexy}
x=y
\end{equation}
and
\begin{equation}\label{eqn:singleyx}
y=x
\end{equation}
Referencing using \texttt{$\backslash$cref}: \cref{eqn:singlexy}, \cref{eqn:singleyx}.
Referencing using \texttt{$\backslash$labelcref}: \labelcref{eqn:singlexy}, \labelcref{eqn:singleyx}. $\leftarrow$ Parenthesis are \emph{not} missing for normal equations!
\end{document}
输出:
奇怪的是,对于equation
s 您必须使用\creflabelformat
和\crefrangelabelformat
。
答案2
就我而言
\crefalias{subequation}{equation}
序言中是这个问题的最佳解决方案。(我是从这个答案到其他人也问过同样的问题。
这个解决方案的最大优点是
\labelcref{equation1,subequation2a)
\labelcref{eqn:singlexy,eqn:abc2} %in your example
也可以。(在接受的解决方案这行不通。)此解决方案的其他优点包括:
- 只需在序言中添加一行。
- 你不必考虑不同的语言
- 你不必考虑这样的修改
\newcommand{\crefrangeconjunction}{--}
这个(\crefalias{subequation}{equation}
)解决方案有什么缺点吗?
答案3
我发现该\namecref
命令也不起作用,给出??
输出,所以我在序言中添加了以下行:
\crefname{subequation}{eq.}{eqs.}
但是,使用该命令时,子方程及其父方程周围的括号就会消失\cref
...因此,还必须添加以下两行:
\creflabelformat{subequation}{#2(#1)#3}
\crefrangelabelformat{subequation}{#3(#1)#4 to #5(#2)#6}
因此,完整的代码如下:
\documentclass{article}
\usepackage{parskip}
\usepackage{amsmath}
\usepackage[colorlinks]{hyperref}
\usepackage[all]{hypcap}
\usepackage{cleveref}
%
% Change so that the parentheses for equations are part of the hyperlink
\creflabelformat{equation}{#2(#1)#3}
\crefrangelabelformat{equation}{#3(#1)#4 to #5(#2)#6}
%
% Make \cref, \labelcref and \namecref work as intended with subequations
\labelcrefformat{subequation}{#2(#1)#3}
\labelcrefrangeformat{subequation}{#3(#1)#4 to #5(#2)#6}
\crefname{subequation}{eq.}{eqs.}
\creflabelformat{subequation}{#2(#1)#3}
\crefrangelabelformat{subequation}{#3(#1)#4 to #5(#2)#6}
%
\begin{document}
\textbf{Writing three subequations:}
\begin{subequations}\label{eqn:abc}
\begin{align}
A&=B\label{eqn:abc1}\\
B&=C\label{eqn:abc2}\\
C&=A\label{eqn:abc3}
\end{align}
\end{subequations}
Referencing using \texttt{$\backslash$cref}: \cref{eqn:abc}, \cref{eqn:abc1}, \cref{eqn:abc2}, \cref{eqn:abc3}.
Referencing using \texttt{$\backslash$labelcref}: \labelcref{eqn:abc}, \labelcref{eqn:abc1}, \labelcref{eqn:abc2}, \labelcref{eqn:abc3}.
Referencing using \texttt{$\backslash$namecref}: \namecref{eqn:abc}, \namecref{eqn:abc1}, \namecref{eqn:abc2}, \namecref{eqn:abc3}.\\[2ex]
\textbf{Writing two separate single equations:}
\begin{equation}\label{eqn:singlexy}
x=y
\end{equation}
and
\begin{equation}\label{eqn:singleyx}
y=x
\end{equation}
Referencing using \texttt{$\backslash$cref}: \cref{eqn:singlexy}, \cref{eqn:singleyx}.
Referencing using \texttt{$\backslash$labelcref}: \labelcref{eqn:singlexy}, \labelcref{eqn:singleyx}.
Referencing using \texttt{$\backslash$namecref}: \namecref{eqn:singlexy}, \namecref{eqn:singleyx}.
\end{document}
输出结果如下:
答案4
\labelcref
等\namecref
似乎可以与我网站上提供的最新预发布版本 (0.21) 中的子方程正确配合使用:http://www.dr-qubit.org/latex.html