如何对齐多个 eqnarray?

如何对齐多个 eqnarray?

我尝试创建 2 eqnarray,但这些 2 中的方程式eqnarray不一致。代码如下:

\documentclass{article}
\usepackage[fleqn]{amsmath}
\usepackage{txfonts}
\begin{document}
\begin{eqnarray}
\label{eq1}
&& diag\frac{\partial P}{\partial \theta}= 
diag(-diag(V)[Gdiag(V)\sin(Abus)^{T}-Bdiag(V)cos(Abus)^{T}]
\nonumber\\
&& -diag(V).^{2}diag(diag(B))))  \\
\label{eq2}
&& nondiag\frac{\partial P}{\partial \theta}= 
VV^{T}.* G .* \sin(Abus) -VV^{T}.*B .* \cos(Abus)   
\end{eqnarray}
Replace the diagnol elements of the (\ref{eq2}) with the elements of the                
(\ref{eq1}), we will get the complete $\partial P/\partial \theta$
\begin{eqnarray}
\label{eq3}
&& diag\frac{\partial P}{\partial V}=
diag(Gdiag(V)\cos(Abus)^{T}+Bdiag(V)sin(Abus)^{T}
\nonumber\\
&& +diag(V)diag(diag(G))))  \\
\label{eq4}
&& nondiag\frac{\partial P}{\partial V}= 
diag(V)G .* \cos(Abus) + diag(V)B .* \sin(Abus)   
\end{eqnarray}
Replace the diagnol elements of the (\ref{eq4}) with the elements of the    
(\ref{eq3}), we will get the complete $\partial P/\partial V$
\end{document}

结果是: 我们可以看到方程(1)、(2)和方程(3)、(4)的起始位置不同。我该如何解决这个问题?谢谢。

答案1

eqnarray用结果替换align并不完全对齐,但我看起来像是,而且我认为比用更好eqnarray

根据 Ian 的建议diag,和nondiag被声明为数学运算符。括号大小也已调整。

在 Mico 的评论之后,dotstar已经宣布了一条新命令。我不清楚它的作用是什么。

\documentclass{article}
\usepackage[fleqn]{amsmath}
\usepackage{txfonts}

\DeclareMathOperator{\diag}{diag}
\DeclareMathOperator{\nondiag}{nondiag}
\newcommand\dotstar{\mathbin{.*}}

\begin{document}
\begin{align}
\label{eq1}
\diag\frac{\partial P}{\partial \theta} & = 
\diag\left(-\diag(V)\left[Gdiag(V)\sin(Abus)^{T}-B\diag(V)cos(Abus)^{T}\right]\right.
\nonumber\\
&\quad \left.-\diag(V).^{2}\diag\left(\diag(B)\right)\right)  \\
\label{eq2}
\nondiag\frac{\partial P}{\partial \theta} & = 
VV^{T}\dotstar G\dotstar\sin(Abus)-VV^{T}\dotstar B\dotstar\cos(Abus)   
\end{align}
Replace the diagnol elements of the (\ref{eq2}) with the elements of the                
(\ref{eq1}), we will get the complete $\partial P/\partial \theta$
\begin{align}
\label{eq3}
\diag\frac{\partial P}{\partial V} & =
\diag\left(G\diag(V)\cos(Abus)^{T}+B\diag(V)sin(Abus)^{T}\right.
\nonumber\\
&\quad +\Bigl.\diag(V)\diag\left(\diag(G)\right)\Bigr)  \\
\label{eq4}
\nondiag\frac{\partial P}{\partial V}&= 
\diag(V)G\dotstar\cos(Abus) + \diag(V)B\dotstar\sin(Abus)   
\end{align}
Replace the diagnol elements of the (\ref{eq4}) with the elements of the    
(\ref{eq3}), we will get the complete $\partial P/\partial V$
\end{document}

在此处输入图片描述

但是如果您希望所有方程式都完全对齐,请在命令中插入中间段落\intertext

\documentclass{article}
\usepackage[fleqn]{amsmath}
\usepackage{txfonts}

\DeclareMathOperator{\diag}{diag}
\DeclareMathOperator{\nondiag}{nondiag}
\newcommand\dotstar{\mathbin{.*}}

\begin{document}
\begin{align}
\label{eq1}
\diag\frac{\partial P}{\partial \theta} & = 
\diag\left(-\diag(V)\left[Gdiag(V)\sin(Abus)^{T}-B\diag(V)cos(Abus)^{T}\right]\right.
\nonumber\\
&\quad \left.-\diag(V).^{2}\diag\left(\diag(B)\right)\right)  \\
\label{eq2}
\nondiag\frac{\partial P}{\partial \theta} & = 
VV^{T}\dotstar G\dotstar\sin(Abus)-VV^{T}\dotstar B\dotstar\cos(Abus)   
%\end{align}
\intertext{Replace the diagnol elements of the (\ref{eq2}) with the elements of the                
(\ref{eq1}), we will get the complete $\partial P/\partial \theta$}
%\begin{align}
\label{eq3}
\diag\frac{\partial P}{\partial V} & =
\diag\left(G\diag(V)\cos(Abus)^{T}+B\diag(V)sin(Abus)^{T}\right.
\nonumber\\
&\quad +\Bigl.\diag(V)\diag\left(\diag(G)\right)\Bigr)  \\
\label{eq4}
\nondiag\frac{\partial P}{\partial V}&= 
\diag(V)G\dotstar\cos(Abus) + \diag(V)B\dotstar\sin(Abus)   
\end{align}
Replace the diagnol elements of the (\ref{eq4}) with the elements of the    
(\ref{eq3}), we will get the complete $\partial P/\partial V$
\end{document}

在此处输入图片描述

答案2

切勿使用eqnarray(见eqnarray 与 align

align这里与的结合split似乎是解决问题的最佳方法。

\documentclass{article}
\usepackage{mathtools}
\usepackage{newtxtext,newtxmath}

\DeclareMathOperator{\diag}{diag}
\DeclareMathOperator{\nondiag}{nondiag}
\newcommand{\dotstar}{\mathbin{.{*}}}
\newcommand{\Abus}{\mathit{Abus}}

\begin{document}

\begin{align}
\begin{split}
\diag\frac{\partial P}{\partial \theta} & = 
\diag\bigl(-\diag(V)[G \diag(V)\sin(\Abus)^{T}-B\diag(V)\cos(\Abus)^{T}]\\
&\qquad -\diag(V)^{2}\diag(\diag(B))\bigr)
\end{split}
\label{eq1} \\
\nondiag\frac{\partial P}{\partial \theta} & = 
VV^{T}\dotstar G\dotstar \sin(\Abus)-VV^{T}\dotstar B\cos(\Abus)   
\label{eq2}\\
\intertext{%
  By replacing the diagonal elements of the (\ref{eq2}) with the elements of
  equation~\eqref{eq1}, we will get the complete $\partial P/\partial \theta$}
\begin{split}
\diag\frac{\partial P}{\partial V} & =
  \diag\bigl(G\diag(V)\cos(\Abus)^{T}+B\diag(V)\sin(\Abus)^{T} \\
&\qquad +\diag(V)\diag(\diag(G))\bigr)
\end{split}
\label{eq3}\\
\nondiag\frac{\partial P}{\partial V}&= 
\diag(V)G\dotstar \cos(\Abus) + \diag(V)B\dotstar \sin(\Abus)   
\label{eq4}
\end{align}
By replacing the diagonal elements of equation~\eqref{eq4} with the elements of
equation~\eqref{eq3}, we will get the complete $\partial P/\partial V$

\end{document}

txfontsnewtxtext和替换了newtxmath(数学字体更好,并且包得到积极维护)。

如果将tbtags选项添加到amsmath方程式中,则编号将与零件的底线对齐split

我删除了所有内容\left,但\right这样做毫无用处(它们只是增加了不必要的水平空间)。只\big需要几对。

在此处输入图片描述

答案3

在一个对齐环境中使用 intertext 可获得对齐:

\documentclass{article}
\usepackage[fleqn]{amsmath}
\usepackage{txfonts}
\begin{document}
\begin{align}
\label{eq1}
& diag\frac{\partial P}{\partial \theta}= 
diag(-diag(V)[Gdiag(V)\sin(Abus)^{T}-Bdiag(V)cos(Abus)^{T}]
\nonumber\\
& -diag(V).^{2}diag(diag(B))))  \\
\label{eq2}
& nondiag\frac{\partial P}{\partial \theta}= 
VV^{T}.* G .* \sin(Abus) -VV^{T}.*B .* \cos(Abus)   
\intertext{Replace the diagnol elements of the (\ref{eq2}) with the     elements of the                
(\ref{eq1}), we will get the complete $\partial P/\partial \theta$}
\label{eq3}
&diag\frac{\partial P}{\partial V}=
diag(Gdiag(V)\cos(Abus)^{T}+Bdiag(V)sin(Abus)^{T}
   \nonumber\\
& +diag(V)diag(diag(G))))  \\
\label{eq4}
  & nondiag\frac{\partial P}{\partial V}= 
   diag(V)G .* \cos(Abus) + diag(V)B .* \sin(Abus)   
 \end{align}
    Replace the diagnol elements of the (\ref{eq4}) with the elements        of    the    
(\ref{eq3}), we will get the complete $\partial P/\partial V$
\end{document}

相关内容