混合子方程与引用母方程的能力一致

混合子方程与引用母方程的能力一致

我一直在使用这个问题为了在对齐环境中拥有混合方程和子方程编号,MWE:

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{etoolbox}
\usepackage[breaklinks=true, linkcolor=blue, citecolor=blue, colorlinks=true]{hyperref}

% subequations inside of align
% https://tex.stackexchange.com/questions/34566/mixed-subequation-numbering-within-an-array
\AtBeginEnvironment{align}{\setcounter{subeqn}{0}}% Reset subequation number at start of align
\newcounter{subeqn} \renewcommand{\thesubeqn}{\theequation\alph{subeqn}}%
\newcommand{\subeqn}{%
  \refstepcounter{subeqn}% Step subequation number
  \tag{\thesubeqn}% Label equation
}
\newcommand{\beginsubeqn}{\setcounter{subeqn}{0}\refstepcounter{equation}\subeqn}

\begin{document}
\begin{align}
 \frac{\partial A }{\partial x } &= a &\;,& \label{e:first} \\
 \frac{\partial A }{\partial y } &= b &\;,& \label{e:second} \\
 \intertext{and:}
 \frac{\partial A}{\partial z } &= c &\text{if type Z,}&\beginsubeqn \\
 \frac{\partial A }{\partial w } &= d &\text{if type W,}&\subeqn
 \label{e:last}
\end{align} 

Eqs.~\ref{e:first}~and~\eqref{e:second} are fine, but I'd like Eq.~\ref{e:last} to show as Eq.~(3).
It's easy to do with a regular `subequations` environment:
\begin{subequations}
 \label{e:goodref}
 \begin{align}
  a&=b \\
  b&=c
 \end{align}
\end{subequations}
See? Eq.~\ref{e:goodref}.
\end{document}

结果:

在此处输入图片描述

但是,这有点不符合我的要求。我需要能够将子方程式作为单个方程式引用。使用子方程式环境(参见 MWE)可以轻松实现这一点,但不幸的是,它在对齐中会中断。

这可能吗?

编辑:我发现了一个使用 cleverref 和 xstring 的 hackish 解决方案:

\documentclass[12pt]{article}
\usepackage{etoolbox}
\usepackage{amsmath}
\usepackage{xstring}
\usepackage[breaklinks=true, linkcolor=blue, citecolor=blue, colorlinks=true]{hyperref}
\usepackage[english,capitalise]{cleveref}

% subequations inside of align
% https://tex.stackexchange.com/questions/34566/mixed-subequation-numbering-within-an-array
\AtBeginEnvironment{align}{\setcounter{subeqn}{0}}% Reset subequation number at start of align
\newcounter{subeqn} \renewcommand{\thesubeqn}{\theequation\alph{subeqn}}%
\newcommand{\subeqn}{%
  \refstepcounter{subeqn}% Step subequation number
  \tag{\thesubeqn}% Label equation
}
\newcommand{\beginsubeqn}{\setcounter{subeqn}{0}\refstepcounter{equation}\subeqn}

% remove last character if letter
\newcommand{\removeendalpha}[1]{\expandarg\def\last{\StrRight{#1}{1}}\def\withoutlast{\StrGobbleRight{#1}{1}}\IfInteger{\last}{#1}{\withoutlast}}


% define cref that labels subequations as parent
\crefname{subasparent}{eq.}{eqs.}
\crefformat{subasparent}{(#2\removeendalpha{#1}#3)}

\begin{document}
\begin{align}
 \frac{\partial A }{\partial x } &= a &\;,& \label{e:first} \\
 \frac{\partial A }{\partial y } &= b &\;,& \label{e:second} \\
 \intertext{and:}
 \label[subasparent]{e:last}
 \frac{\partial A}{\partial z } &= c &\text{if type Z,}&\beginsubeqn \\
 \frac{\partial A }{\partial w } &= d &\text{if type W,}&\subeqn
\end{align} 

\cref{e:first,e:second,e:last}, I'd like~\cref{e:last} to show as Eq.~(3).
It's easy to do with a regular `subequations` environment:
\begin{subequations}
 \label{e:goodref}
 \begin{align}
  a&=b \\
  b&=c
 \end{align}
\end{subequations}
See?~\cref{e:goodref}.
\end{document}

在此处输入图片描述

但是现在我不知道如何让参考文献中的“Eq.”部分出现,而且方程式不再正确地组合(...方程式 (1) 和 (2) 和 (3) 而不是方程式 (1) 至 (3))

edit2:使用 Werner 的建议实施

\documentclass[12pt]{article}
\usepackage{amsmath,amssymb,eqparbox}
\usepackage[breaklinks=true, linkcolor=blue, citecolor=blue, colorlinks=true]{hyperref}
\usepackage[english,capitalise]{cleveref}

\begin{document}
\begin{align}
 \frac{\partial [X]_i }{\partial T } &= - \frac{[C] \alpha_{{N_s},i}}{T} & \eqmakebox[cond][r]{,} \label{e:dci_thd_dt} \\
 \frac{\partial [X]_i }{\partial n_{j} } &= \frac{1}{V} \left(- \alpha_{{N_s},i} + \alpha_{j,i}\right) & \eqmakebox[cond][r]{,} \label{e:dci_thd_dnj}
\end{align}
and:
\begin{subequations}
 \label{e:dci_thd_de}
 \begin{align}
  \frac{\partial [X]_i }{\partial V } &= \frac{1}{V} \left([C] \alpha_{{N_s},i} - [X]_{i}\right) & \eqmakebox[cond][r]{,\qquad\text{for CONP}}\\
  \frac{\partial [X]_i }{\partial P } &= \frac{\alpha_{{N_s},i}}{T R_u} & \eqmakebox[cond][r]{,\qquad\text{for CONV}}
 \end{align}
\end{subequations}
\end{document}

我有轻微地等号中的对齐被破坏(在我的实际文档中更为明显):

在此处输入图片描述

答案1

我将混合的align-and-拆分\intertext为两个单独的aligns,后者使用subequations环境。然后,当然,你只能尝试摆弄长度以确保 salign仍然在原始 上水平对齐\intertext。为此,eqparbox可以提供帮助。将构造内容设置在会自动更改为最大元素大小的框中。

在此处输入图片描述

\documentclass{article}

\usepackage{amsmath,eqparbox,xparse}
\usepackage{hyperref}

% https://tex.stackexchange.com/a/34412/5764
\makeatletter
\NewDocumentCommand{\eqmathbox}{o O{c} m}{%
  \IfValueTF{#1}
    {\def\eqmathbox@##1##2{\eqmakebox[#1][#2]{$##1##2$}}}
    {\def\eqmathbox@##1##2{\eqmakebox{$##1##2$}}}
  \mathpalette\eqmathbox@{#3}
}
\makeatother

\begin{document}

\begin{align}
    \eqmathbox[LHS][r]{ 123\frac{\partial A}{\partial x}} &= \eqmathbox[RHS][l]{abcd}           & \eqmakebox[cond][r]{,} \label{e:first} \\
    \eqmathbox[LHS][r]{  45\frac{\partial A}{\partial y}} &= \eqmathbox[RHS][l]{e}              & \eqmakebox[cond][r]{,} \label{e:second}
\end{align}
and:
\begin{subequations}
  \label{e:last}
  \begin{align}
    \eqmathbox[LHS][r]{   6\frac{\partial A}{\partial z}} &= \eqmathbox[RHS][l]{fghijkl}        & \eqmakebox[cond][r]{if type $Z$,} \\
    \eqmathbox[LHS][r]{7890\frac{\partial A}{\partial w}} &= \eqmathbox[RHS][l]{mnopqrstuvwxyz} & \eqmakebox[cond][r]{if type $W\!$,}
  \end{align} 
\end{subequations}

Eqs.~\eqref{e:first}~and~\eqref{e:second} are fine, but I'd like Eq.~\eqref{e:last} to show as Eq.~(3).
It's easy to do with a regular \verb|subequations| environment:
\begin{subequations}
  \label{e:goodref}
  \begin{align}
    a &= b \\
    b &= c
  \end{align}
\end{subequations}

See? Eq.~\eqref{e:goodref}.

\end{document}

在上述代码中,\eqmakebox[<tag>][<align>]{<stuff>}将确保所有<stuff>相同的<tag>框都具有相同的最大宽度。可以<align>根据需要设置单个框(默认为c输入)。但是,<stuff>始终在文本模式下设置。我们使用\mathpalette捕获当前数学样式(\displaystyle\textstyle\scriptstyle之一\scriptscriptstyle)并使用它来设置<stuff>适当的样式,所有内容都包裹在 内\eqmathbox

为了演示,我在左侧、右侧和条件中添加了一些内容,只是为了向您展示用例的灵活性。由于eqparbox使用类似于\label-\ref的评估过程来确定每个 的最宽框宽度,因此每当特定 内发生变化<tag>时,至少需要进行两次编译,以使引用(计算)稳定下来。<stuff><tag>

相关内容