如何在“对齐”中将数字方程垂直居中,并在等号后折行缩进方程?

如何在“对齐”中将数字方程垂直居中,并在等号后折行缩进方程?

我想要输入这样的数学方程式: 在此处输入图片描述 但是使用此代码我无法获得上述结果。有人可以帮我编辑代码以获得上述结果吗?

\documentclass{book}
\usepackage{amsmath}
\begin{document}
\begin{align}
    u_j^{n+1}&=u_j^{n}-a(t_n)\Delta t \dfrac{\partial u}{\partial x}
    +\dfrac{(\Delta t)^2}{2}\left(a(t_n)^2\dfrac{\partial^2 u}{\partial x^2}-\dfrac{da(t_n)}{dt}\dfrac{\partial u}{\partial x}\right)\nonumber\\
    &=u_j^{n}-a(t_n)\Delta t \dfrac{\partial u}{\partial x}
    +a(t_n)^2\dfrac{(\Delta t)^2}{2}\dfrac{\partial^2 u}{\partial x^2}-\dfrac{da(t_n)}{dt}\dfrac{(\Delta t)^2}{2}\dfrac{\partial u}{\partial x}\nonumber\\
    &=u_j^{n}-a(t_n)\Delta t \left(\dfrac{u_{j+1}^{n}-u_{j-1}^{n}}{2\Delta x}\right)+a(t_n)^2\dfrac{(\Delta t)^2}{2}\left(\dfrac{u_{j+1}^{n}-2u_{j}^{n}+u_{j-1}^{n}}{(\Delta x)^2}\right)\nonumber\\
    %%%%%%%%%%%%%%%%%%%%%%
    &-\dfrac{da(t_n)}{dt}\dfrac{(\Delta t)^2}{2}\left(\dfrac{u_{j+1}^{n}-u_{j-1}^{n}}{2\Delta x}\right)\nonumber\\
    \begin{aligned}
    &= u_j^{n}-\dfrac{1}{2}\nu_n\left(u_{j+1}^{n}-u_{j-1}^{n}\right)
    +\dfrac{1}{2}\nu_n^2 \left(u_{j+1}^{n}-2u_{j}^{n}+u_{j-1}^{n}\right)
    -\dfrac{da(t_n)}{dt}\dfrac{(\Delta t)^2}{4\Delta x}\left(u_{j+1}^{n}-u_{j-1}^{n}\right)
    \end{aligned}
    \end{align}
\end{document}

答案1

对于居中的方程编号,使用equationaligned,而不是align。对于缩进,我\qquad在需要的地方插入。我还必须拆分您的一条长线,以便为居中的方程编号腾出空间。

\documentclass{book}
\usepackage{amsmath}
\begin{document}
\begin{equation}
\begin{aligned}
    u_j^{n+1}&=u_j^{n}-a(t_n)\Delta t \dfrac{\partial u}{\partial x}
    +\dfrac{(\Delta t)^2}{2}\left(a(t_n)^2\dfrac{\partial^2 u}{\partial x^2}-\dfrac{da(t_n)}{dt}\dfrac{\partial u}{\partial x}\right)\\
    &=u_j^{n}-a(t_n)\Delta t \dfrac{\partial u}{\partial x}
    +a(t_n)^2\dfrac{(\Delta t)^2}{2}\dfrac{\partial^2 u}{\partial x^2}-\dfrac{da(t_n)}{dt}\dfrac{(\Delta t)^2}{2}\dfrac{\partial u}{\partial x}\\
    &=u_j^{n}-a(t_n)\Delta t \left(\dfrac{u_{j+1}^{n}-u_{j-1}^{n}}{2\Delta x}\right)\\
  &\qquad+a(t_n)^2\dfrac{(\Delta t)^2}{2}\left(\dfrac{u_{j+1}^{n}-2u_{j}^{n}+u_{j-1}^{n}}{(\Delta x)^2}\right)\\
    %%%%%%%%%%%%%%%%%%%%%%
    &\qquad-\dfrac{da(t_n)}{dt}\dfrac{(\Delta t)^2}{2}\left(\dfrac{u_{j+1}^{n}-u_{j-1}^{n}}{2\Delta x}\right)\\
    &= u_j^{n}-\dfrac{1}{2}\nu_n\left(u_{j+1}^{n}-u_{j-1}^{n}\right)
    +\dfrac{1}{2}\nu_n^2 \left(u_{j+1}^{n}-2u_{j}^{n}+u_{j-1}^{n}\right)\\
   &\qquad-\dfrac{da(t_n)}{dt}\dfrac{(\Delta t)^2}{4\Delta x}\left(u_{j+1}^{n}-u_{j-1}^{n}\right)
    \end{aligned}
\end{equation}
\end{document}

在此处输入图片描述


附录

原帖作者的评论对期望给出了不同的解释。希望这符合期望。

\documentclass{book}
\usepackage{amsmath}
\begin{document}
\begin{align}
    u_j^{n+1}&=u_j^{n}-a(t_n)\Delta t \dfrac{\partial u}{\partial x}
    +\dfrac{(\Delta t)^2}{2}\left(a(t_n)^2\dfrac{\partial^2 u}{\partial x^2}-\dfrac{da(t_n)}{dt}\dfrac{\partial u}{\partial x}\right)\nonumber\\
    &=u_j^{n}-a(t_n)\Delta t \dfrac{\partial u}{\partial x}
    +a(t_n)^2\dfrac{(\Delta t)^2}{2}\dfrac{\partial^2 u}{\partial x^2}-\dfrac{da(t_n)}{dt}\dfrac{(\Delta t)^2}{2}\dfrac{\partial u}{\partial x}\nonumber\\
    &=u_j^{n}-a(t_n)\Delta t \left(\dfrac{u_{j+1}^{n}-u_{j-1}^{n}}{2\Delta x}\right)
  \nonumber\\
  &\qquad+a(t_n)^2\dfrac{(\Delta t)^2}{2}\left(\dfrac{u_{j+1}^{n}-2u_{j}^{n}+u_{j-1}^{n}}{(\Delta x)^2}\right)\nonumber\\
    %%%%%%%%%%%%%%%%%%%%%%
    &\qquad-\dfrac{da(t_n)}{dt}\dfrac{(\Delta t)^2}{2}\left(\dfrac{u_{j+1}^{n}-u_{j-1}^{n}}{2\Delta x}\right)\nonumber\\
    & 
\begin{aligned}
{} &= u_j^{n}-\dfrac{1}{2}\nu_n\left(u_{j+1}^{n}-u_{j-1}^{n}\right)
    +\dfrac{1}{2}\nu_n^2 \left(u_{j+1}^{n}-2u_{j}^{n}+u_{j-1}^{n}\right)\\ 
  &\qquad-\dfrac{da(t_n)}{dt}\dfrac{(\Delta t)^2}{4\Delta x}\left(u_{j+1}^{n}-u_{j-1}^{n}\right)
\end{aligned}
    \end{align}
\end{document}

在此处输入图片描述

相关内容