我希望文本中出现的“方程编号”与方程中出现的“方程编号”不同。例如,如果我有
\begin{equation}
a=b
\tag{1}
\reftag{2}
\label{eqn}
\end{equation}
\eqref{eqn}
那么方程应该有(1),但引用的是(2)。这可能吗?
编辑:背景
我正在尝试这样做,以便可以并排有两个子方程。我当前的解决方案如下:
\newlength{\sbsseLl}
\newlength{\sbsseLr}
\newlength{\sbsseLe}
\newlength{\sbsseLle}
\newlength{\sbsseLre}
\newlength{\sbsseLt}
\newcommand{\sidebysidesubequations}[6]{%
% #1 reference label
% #2 left subequation
% #3 left label
% #4 midtext
% #5 right subequation
% #6 right label
%
%Setup the equations to be typed
\def\sbsseEl{#2}
\def\sbsseEr{\ifstrempty{#4}{#5}{\textrm{#4} \qquad #5}}
%Compute the width of the left and right side equations as inputted
\settowidth{\sbsseLl}{\begin{math}\displaystyle\sbsseEl\end{math}}
\settowidth{\sbsseLr}{\begin{math}\displaystyle\sbsseEr\end{math}}
\settowidth{\sbsseLt}{(\ref*{#1}a,b)}
%\setlength{\sbsseLt}{\sbsseLt+15mm}
%Compute the extra length to give to each
\setlength{\sbsseLe}{(\linewidth-\sbsseLl-\sbsseLr-\sbsseLt)/2}
\setlength{\sbsseLle}{\sbsseLl+\sbsseLe}
\setlength{\sbsseLre}{\sbsseLr+\sbsseLt+\sbsseLe}
%Construct table with these widths and place equations in cells
\noindent
\begin{subequations}\label{#1}
\begin{tabular}{@{}p{\sbsseLle}@{}p{\sbsseLre}@{}}%p{\sbsseLte}@{}}
\begin{equation}
\sbsseEl \vphantom{\sbsseEr}
\label{#3} \tag*{}
\end{equation}
\renewcommand\theequation{abc}\label{eqn:my}
&
\begin{equation}
\sbsseEr \vphantom{\sbsseEl}
\label{#6} \tag*{(\ref*{#1}a,b)}
\end{equation}
\end{tabular}
\end{subequations}
\newline
}
通过此设置,我可以编写\sidebysidesubequations{eqn:all}{a=b}{eqn:left}{and}{c=d}{eqn:right}
并获得两个与方程编号并排格式化的方程,例如 (1a,b)。但是,\ref{eqn:left}
当应为 1a 时,它给出了一个空引用,而\ref{eqn:right}
当应为 1b 时,它给出了引用 1a,b。我想要做的是修改引用,以便我可以为每个子方程分配正确的标签,并且仍然将所有引用放在行末。
编辑 2:最小工作示例
\documentclass{article}
\usepackage{amsmath}
\usepackage[hidelinks]{hyperref}
\usepackage{cleveref}
\usepackage{calc,etoolbox}
\newlength{\sbsseLl}
\newlength{\sbsseLr}
\newlength{\sbsseLe}
\newlength{\sbsseLle}
\newlength{\sbsseLre}
\newlength{\sbsseLt}
\newcommand{\sidebysidesubequations}[6]{%
% #1 reference label
% #2 left subequation
% #3 left label
% #4 midtext
% #5 right subequation
% #6 right label
%
%Setup the equations to be typed
\def\sbsseEl{#2}
\def\sbsseEr{\ifstrempty{#4}{#5}{\textrm{#4} \qquad #5}}
%Compute the width of the left and right side equations as inputted
\settowidth{\sbsseLl}{\begin{math}\displaystyle\sbsseEl\end{math}}
\settowidth{\sbsseLr}{\begin{math}\displaystyle\sbsseEr\end{math}}
\settowidth{\sbsseLt}{(\ref*{#1}a,b)}
%Compute the extra length to give to each
\setlength{\sbsseLe}{(\linewidth-\sbsseLl-\sbsseLr-\sbsseLt)/2}
\setlength{\sbsseLle}{\sbsseLl+\sbsseLe}
\setlength{\sbsseLre}{\sbsseLr+\sbsseLt+\sbsseLe}
%Construct table with these widths and place equations in cells
\noindent
\begin{subequations}\label{#1}
\begin{tabular}{@{}p{\sbsseLle}@{}p{\sbsseLre}@{}}%p{\sbsseLte}@{}}
\begin{equation}
\sbsseEl \vphantom{\sbsseEr}
\label{#3} \tag*{}
\end{equation}
&
\begin{equation}
\sbsseEr \vphantom{\sbsseEl}
\label{#6} \tag{\ref*{#1}a,b}
\end{equation}
\end{tabular}
\end{subequations}
\newline
}
\begin{document}
Here are my equations:
\sidebysidesubequations{eqn:all}{le=ft}{eqn:left}{and}{ri=ght}{eqn:right}
The overall system gets correctly referenced as `\cref{eqn:all}'.
However, the left equation gets incorrectly referenced as `\cref{eqn:left}', it should be `eq. (1a)',
similarly the right gets referenced as `\cref{eqn:right}', it should be `eq. (1b)'.
\end{document}
编辑 3:使用 Werner 的解决方案修复示例
\documentclass{article}
\usepackage{amsmath}
\usepackage[hidelinks]{hyperref}
\usepackage{cleveref}
\usepackage{calc,etoolbox}
\makeatletter
\newlength{\sbsseWl} %Width of left equation
\newlength{\sbsseWm} %Width of mid text
\newlength{\sbsseWr} %Width of right equation
\newlength{\sbsseWt} %Width of tag
\newlength{\sbsseWe} %Remaining width on line
\newlength{\sbsseWd} %Remaining width divided into pieces
\newcommand{\sidebysidesubequations}[6]{%
% #1 reference label
% #2 left subequation
% #3 left label
% #4 midtext
% #5 right subequation
% #6 right label
%Setup the equations to be typed
\def\sbsseEl{#2}
\def\sbsseEm{\textrm{#4}}
\def\sbsseEr{#5}
\def\sbsseEt{(\ref*{#1}a,b)}
%Compute the widths
\settowidth{\sbsseWl}{\begin{math}\displaystyle\sbsseEl\end{math}}
\settowidth{\sbsseWm}{\begin{math}\displaystyle\sbsseEm\end{math}}
\settowidth{\sbsseWr}{\begin{math}\displaystyle\sbsseEr\end{math}}
\settowidth{\sbsseWt}{\sbsseEt}
\setlength{\sbsseWe}{\linewidth-\sbsseWl-\sbsseWm-\sbsseWr-\sbsseWt}
%Beigin equation typesetting, with label for overall subequations
\begin{subequations}\ltx@label{{#1}}
\begin{displaymath}
%Left equation and label
\sbsseEl\refstepcounter{equation}\ltx@label{{#3}}
%Space, and midtext if any
\if\relax\detokenize{#4}\relax
\setlength{\sbsseWd}{\sbsseWe/3}
\hspace{\sbsseWd}
\else
\setlength{\sbsseWd}{\sbsseWe/4}
\hspace{\sbsseWd}\sbsseEm\hspace{\sbsseWd}
\fi
%Right equation and label
\sbsseEr\refstepcounter{equation}\ltx@label{{#6}}
%Tag
\tag*{\sbsseEt}
\end{displaymath}
\end{subequations}
}
\makeatother
\begin{document}
Here are my equations:
\sidebysidesubequations{eqn:all}{le=ft}{eqn:left}{and}{ri=ght}{eqn:right}
The overall system gets referenced as `\cref{eqn:all}', the left equation gets referenced as `\cref{eqn:left}', the right gets referenced as `\cref{eqn:right}'.
\end{document}
答案1
\sidebysidesubequations
以下是一个可以工作的实现:
\documentclass{article}
\usepackage{amsmath}
\usepackage{hyperref}
\makeatletter
\newcommand{\sidebysidesubequations}[6]{%
% #1 reference label
% #2 left subequation
% #3 left label
% #4 midtext
% #5 right subequation
% #6 right label
%
\begin{subequations}
\ltx@label{#1}%
\[
#2\refstepcounter{equation}\ltx@label{#3}
% https://tex.stackexchange.com/a/53091/5764
\if\relax\detokenize{#4}\relax
\qquad
\else
\quad\text{#4}\quad
\fi
#5\refstepcounter{equation}\ltx@label{#6}
\tag*{(\ref*{#1}a,b)}
\]
\end{subequations}
}
\makeatother
\begin{document}
See equations~\eqref{eqn:left} and~\eqref{eqn:right}.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam quam ligula,
venenatis ut mi non, feugiat imperdiet purus. Donec scelerisque suscipit
mauris euismod maximus. Nunc lacus diam, efficitur in justo ac, imperdiet
ultrices dolor. Nulla sed luctus massa. Vestibulum ornare venenatis justo
malesuada sagittis. Etiam tempus nec lorem quis commodo.
\sidebysidesubequations{eqn:all}{a=b}{eqn:left}{and}{c=d}{eqn:right}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam quam ligula,
venenatis ut mi non, feugiat imperdiet purus. Donec scelerisque suscipit
mauris euismod maximus. Nunc lacus diam, efficitur in justo ac, imperdiet
ultrices dolor. Nulla sed luctus massa. Vestibulum ornare venenatis justo
malesuada sagittis. Etiam tempus nec lorem quis commodo.
\clearpage
See equation~\eqref{eqn:other}.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam quam ligula,
venenatis ut mi non, feugiat imperdiet purus. Donec scelerisque suscipit
mauris euismod maximus. Nunc lacus diam, efficitur in justo ac, imperdiet
ultrices dolor. Nulla sed luctus massa. Vestibulum ornare venenatis justo
malesuada sagittis. Etiam tempus nec lorem quis commodo.
\begin{align}
a &= b & c &= d \label{eqn:other}
\end{align}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam quam ligula,
venenatis ut mi non, feugiat imperdiet purus. Donec scelerisque suscipit
mauris euismod maximus. Nunc lacus diam, efficitur in justo ac, imperdiet
ultrices dolor. Nulla sed luctus massa. Vestibulum ornare venenatis justo
malesuada sagittis. Etiam tempus nec lorem quis commodo.
\end{document}
两页的输出只是为了比较。