用两个等号对齐方程

用两个等号对齐方程

我正在尝试写三个等式,第二个等式有两个等号。我希望前两个等式与第一个等号对齐,第二个和第三个等式与第二个等号对齐。我有以下代码:

\documentclass[a4paper]{article}
\usepackage{mathtools}
\usepackage{amssymb}

\newcommand{\ddn}[2]{\frac{\mathrm{d}}{\mathrm{d} #1 } #2 }
\newcommand{\ddt}{\frac{\mathrm{d}}{\mathrm{d} t } }

\begin{document}
\begin{eqnarray}
x'(t)&=&\ddt\left(\left[-\frac{M}{\omega^2}\cos{(\omega t)}+B_1\sin{(\omega t)}\right]+
\left[\frac{M}{\omega^2}-\frac{M}{T\omega^2}t\right]\right)\\
{}&=&\frac{M}{\omega}\sin{(\omega t)}+B_1\omega\cos{(\omega t)}-\frac{M}{T \omega^2}\\
\therefore x'(0) &=&
\frac{M}{\omega}\sin{(\omega 0)}+B_1\omega\cos{(\omega 0)}-\frac{M}{T \omega^2}=0\\
\therefore B_1\omega-\frac{M}{T\omega^2}&=& 0
\end{eqnarray}
\end{document}

输出结果如下: 原始结果

等式 (1)、(2) 和 (3) 已按要求对齐,但我希望 (4) 与 (3) 中的第二个等号对齐。这可行吗?

答案1

为了实现这种对齐,我会使用\mathllap\mathrlap,但我会将它们与环境结合使用,以确保每行上的符号alignat正确对齐。=

示例代码:

\documentclass[a4paper]{article}
\usepackage{mathtools,amsmathm,amssymb}

\newcommand{\ddn}[2]{\frac{\mathrm{d}}{\mathrm{d}#1}#2}
\newcommand{\ddt}{\frac{\mathrm{d}}{\mathrm{d}t}}

\begin{document}
% Start an equation environment with two sets of aligned equalities
\begin{alignat}{2}
    x'(t) &=
    % RHS "overlaps" anything on its right (occupies no space to its right)
    \mathrlap{\ddt\left(
        \left[-\frac{M}{\omega^2}\cos{(\omega t)}+B_1\sin{(\omega t)}\right] + 
        \left[\frac{M}{\omega^2}-\frac{M}{T\omega^2}t\right]
    \right)}
    % Add a little bit of space on the RHS in the second set of equalities, for balance
    &&\mspace{120mu}
    % Start a new line of the equation but without adding any equation numbers
    \notag\\
    &= \frac{M}{\omega}\sin{(\omega t)}+B_1\omega\cos{(\omega t)}-\frac{M}{T \omega^2}
    % New line and equation number, with some added vertical space
    \\[1.5ex]
    \therefore x'(0) &=
    \frac{M}{\omega}\sin{(\omega 0)}+B_1\omega\cos{(\omega 0)}-\frac{M}{T \omega^2}
    % Second set of equalities
    &&= 0
    % New line and new equation number, with some added vertical space
    \\[1.5ex]
    % Align the new equation at the second set of equalities; LHS "overlaps" anything
    % on its left so that it doesn't push away the second `=' in the previous equation
    && \mathllap{\therefore B_1\omega-\frac{M}{T\omega^2}} &= 0
\end{alignat}
\end{document}

示例输出:

使用“alignat”环境输出多个 ` 符号的对齐

答案2

还有一种可能性:我会中心最后一个方程的符号不会=与前一行的符号对齐。为了增强视觉效果,我还将增加方程 (3) 和 (4) 之间的垂直偏移。

在此处输入图片描述

\documentclass[a4paper]{article}
\usepackage{mathtools,amssymb}

\newcommand{\ddn}[2]{\frac{\mathrm{d}}{\mathrm{d} #1 } #2 }
\newcommand{\ddt}{\frac{\mathrm{d}}{\mathrm{d} t } }

\begin{document}
\begin{align}
x'(t)&=\ddt\left(\left[-\frac{M}{\omega^2}\cos{(\omega t)}+B_1\sin{(\omega t)}\right]+
\left[\frac{M}{\omega^2}-\frac{M}{T\omega^2}t\right]\right)\\
{}&=\frac{M}{\omega}\sin{(\omega t)}+B_1\omega\cos{(\omega t)}-\frac{M}{T \omega^2}\\
x'(0) &= \frac{M}{\omega}\sin{(\omega 0)}+B_1\omega\cos{(\omega 0)}-\frac{M}{T \omega^2}=0\\[2ex]
&\qquad\qquad\quad\therefore B_1\omega-\frac{M}{T\omega^2}= 0
\end{align}
\end{document} 

答案3

我建议还有另一种变体,同样包括alignat

\documentclass[a4paper]{article}
\usepackage{mathtools}
\usepackage{amssymb}
\newcommand{\ddn}[2]{\frac{\mathrm{d}}{\mathrm{d} #1 } #2 }
\newcommand{\ddt}{\frac{\mathrm{d}}{\mathrm{d} t } }

\begin{document}

\begin{alignat}{2}
  x'(t) & = \mathrlap{\ddt\left(\left[-\frac{M}{ω^2}\cos{(ω t)}+B_1\sin{(ω t)}\right]+
  \left[\frac{M}{ω^2}-\frac{M}{Tω^2}t\right]\right)} \\
    & \therefore{} & x'(t){} & = \frac{M}{ω}\sin{(ω t)}+B_1ω \cos{(ω t)}-\frac{M}{T ω^2} \\
    & \therefore{} & x'(0){} & {}=
  \frac{M}{ω}\sin{(ω 0)}+B_1ω \cos{(ω 0)}-\frac{M}{T ω^2} =0\\
  &\therefore{}\mathrlap{B_1\omega-\frac{M}{Tω^2} = 0}
\end{alignat}

\end{document} 

在此处输入图片描述

答案4

使用 amsmath 包和 \begin{align} / \end{align} 设置以获得更紧密的外观。

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{amssymb}

\newcommand{\ddn}[2]{\frac{\mathrm{d}}{\mathrm{d} #1 } #2 }
\newcommand{\ddt}{\frac{\mathrm{d}}{\mathrm{d} t } }

\begin{document}
\begin{align}
x'(t)&=\ddt\left(\left[-\frac{M}{\omega^2}\cos{(\omega t)}+B_1\sin{(\omega t)}\right]+
\left[\frac{M}{\omega^2}-\frac{M}{T\omega^2}t\right]\right) \\
&=\frac{M}{\omega}\sin{(\omega t)}+B_1\omega\cos{(\omega t)}-\frac{M}{T \omega^2} \\
\therefore x'(0) 
&=
\frac{M}{\omega}\sin{(\omega 0)}+B_1\omega\cos{(\omega 0)}-\frac{M}{T \omega^2}=0 \\
& \hspace{34mm} \therefore B_1\omega-\frac{M}{T\omega^2} = 0
\end{align}
\end{document} 

相关内容