如何對齊多個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聲明為數學運算符。括號大小也已調整。

在米科發表評論後,新的命令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在這裡,與的組合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}

txfontsnewtxtextand替換newtxmath(數學字體更好,並且包得到積極維護)。

如果將tbtags選項加入amsmath方程式中,編號將與零件的底線對齊split

我刪除了所有\left內容,\right但沒有任何作用(它們只是添加了不需要的水平空間)。只\big需要幾對。

在此輸入影像描述

答案3

在一個對齊環境中使用互文可以獲得對齊:

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

相關內容