跨 5 行的多行方程对齐

跨 5 行的多行方程对齐

我想以以下方式呈现一个等式:

所需能量方程对齐

然而,利用 amsmath 包,这是我能得到的最好的结果:

\begin{equation}
  \begin{aligned}
   \frac{\partial}{\partial t}\left[\rho\left(e+\frac{V^2}{2}\right)\right]+\nabla \cdot\left[\rho\left(e+\frac{V^2}{2} \vec{V}\right)\right] &\\
   = & \rho \dot{q}+\frac{\partial}{\partial x}\left(k \frac{\partial T}{\partial x}\right)+\frac{\partial}{\partial y}\left(k \frac{\partial T}{\partial y}\right) \\
   \quad+ & \frac{\partial}{\partial z}\left(k \frac{\partial T}{\partial z}\right)-\frac{\partial(u p)}{\partial x}-\frac{\partial(v p)}{\partial y}-\frac{\partial(w p)}{\partial z}+\frac{\partial\left(u \tau_{\mathrm{xx}}\right)}{\partial x} \\
   \quad+ & \frac{\partial\left(u \tau_{\mathrm{yx}}\right)}{\partial y}+\frac{\partial\left(u \tau_{\mathrm{zx}}\right)}{\partial z}+\frac{\partial\left(v \tau_{\mathrm{xy}}\right)}{\partial x}+\frac{\partial\left(v \tau_{\mathrm{yy}}\right)}{\partial y}+\frac{\partial\left(v \tau_{\mathrm{zy}}\right)}{\partial z} \\
   \quad+ & \frac{\partial\left(w \tau_{\mathrm{xz}}\right)}{\partial x}+\frac{\partial\left(w \tau_{\mathrm{yz}}\right)}{\partial y}+\frac{\partial\left(w \tau_{\mathrm{zz}}\right)}{\partial z}+\rho \vec{f} \cdot \vec{V}
   \label{eq:energyeq}
  \end{aligned}
\end{equation}

LaTeX 输出

我想保留方程式标签,尽管它垂直居中于方程式上方,而不是位于最后一行下方。如有任何建议,我将不胜感激。

答案1

我会使用split并垂直对齐所有 + 号。本地命令可以轻松完成这项工作,并\pder大大简化输入。

\documentclass{article}
\usepackage{amsmath}

\newcommand{\pder}[2][]{\frac{\partial#1}{\partial#2}}

\begin{document}

\begin{equation}\label{eq:energyeq}
\newcommand{\locsp}{\hphantom{{}=\rho\dot{q}}}
\begin{split}
  \pder{t} & \left[\rho\left(e+\frac{V^2}{2}\right)\right]
  +\nabla \cdot\left[\rho\left(e+\frac{V^2}{2} \vec{V}\right)\right] \\
  &= \rho \dot{q}+\pder{x}\left(k \pder[T]{x}\right)+\pder{y}\left(k \pder[T]{y}\right)
  \\
  &\locsp
   + \pder{z}\left(k \pder[T]{z}\right)
   - \pder[(up)]{x}-\pder[(vp)]{y}
   - \pder[(wp)]{z}+\pder[(u\tau_{\mathrm{xx}})]{x}
  \\
  &\locsp
   + \pder[(u\tau_{\mathrm{yx}})]{y}
   + \pder[(u\tau_{\mathrm{zx}})]{z}
   + \pder[(v\tau_{\mathrm{xy}})]{x}
   + \pder[(v\tau_{\mathrm{yy}})]{y}
   + \pder[(v\tau_{\mathrm{zy}})]{z}
  \\
  &\locsp
   + \pder[(w\tau_{\mathrm{xz}})]{x}
   + \pder[(w\tau_{\mathrm{yz}})]{y}
   + \pder[(w\tau_{\mathrm{zz}})]{z}
   + \rho \vec{f} \cdot \vec{V}
\end{split}
\end{equation}

\end{document}

在此处输入图片描述

答案2

...只是改变了环境内的对齐方式aligned

在此处输入图片描述

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\begin{equation}
  \begin{aligned}
    \frac{\partial}{\partial t}&\left[ \rho \left( e + \frac{V^2}{2} \right) \right] + \nabla \cdot \left[ \rho \left( e + \frac{V^2}{2} \vec{V} \right) \right] \\
      &= \rho \dot{q} + \frac{\partial}{\partial x} \left (k \frac{\partial T}{\partial x} \right) + \frac{\partial}{\partial y} \left( k \frac{\partial T}{\partial y} \right) \\
      &\phantom{=} + \frac{\partial}{\partial z} \left (k \frac{\partial T}{\partial z} \right) - \frac{\partial (u p)}{\partial x} - \frac{\partial (v p)}{\partial y} - \frac{\partial (w p)}{\partial z} + \frac{\partial \left( u \tau_{\mathrm{xx}} \right)}{\partial x} \\
      &\phantom{=} + \frac{\partial \left( u \tau_{\mathrm{yx}} \right)}{\partial y} + \frac{\partial \left( u \tau_{\mathrm{zx}} \right)}{\partial z} + \frac{\partial \left( v \tau_{\mathrm{xy}} \right)}{\partial x} + \frac{\partial \left( v \tau_{\mathrm{yy}} \right)}{\partial y} + \frac{\partial \left( v \tau_{\mathrm{zy}} \right)}{\partial z} \\
      &\phantom{=} + \frac{\partial\left(w \tau_{\mathrm{xz}}\right)}{\partial x} + \frac{\partial \left( w \tau_{\mathrm{yz}} \right)}{\partial y} + \frac{\partial \left( w \tau_{\mathrm{zz}} \right)}{\partial z} + \rho \vec{f} \cdot \vec{V}
  \end{aligned}
\end{equation}

\end{document}

答案3

除了将第一行的对齐点向左移动之外,您可能还想重新排列 RHS 上的加法项,这样就可以立即清楚地看到 17 个项中的 15 个可以排列成 5 组,每组 3 个项。这种变化的副作用是,对于整个表达式,您只需 4 行(而不是 5 行)即可。

在此处输入图片描述

\documentclass{article}  % or some other suitable document class
\usepackage{amsmath}     % for 'aligned' environment
\usepackage{mleftright}  % optional (for more compact display of parenth. groups)
\mleftright

\begin{document}
\begin{equation} \label{eq:energyeq}
\begin{aligned}
   \frac{\partial}{\partial t} 
   &\left[\rho\left(e+\frac{V^2}{2}\right)\right]
   +\nabla \cdot\left[\rho\left(e+\frac{V^2}{2} \vec{V}\right)\right] \\
   &= \rho \dot{q}+ \rho\vec{f}\cdot\vec{V}
          +\frac{\partial}{\partial x}\left(k \frac{\partial T}{\partial x}\right)
          +\frac{\partial}{\partial y}\left(k \frac{\partial T}{\partial y}\right) 
          +\frac{\partial}{\partial z}\left(k \frac{\partial T}{\partial z}\right)\\
   &\quad -\frac{\partial(u p)}{\partial x}
          -\frac{\partial(v p)}{\partial y}
          -\frac{\partial(w p)}{\partial z}
          +\frac{\partial(u \tau_{\mathrm{xx}})}{\partial x}
          +\frac{\partial(u \tau_{\mathrm{yx}})}{\partial y}
          +\frac{\partial(u \tau_{\mathrm{zx}})}{\partial z}\\
   &\quad +\frac{\partial(v \tau_{\mathrm{xy}})}{\partial x}
          +\frac{\partial(v \tau_{\mathrm{yy}})}{\partial y}
          +\frac{\partial(v \tau_{\mathrm{zy}})}{\partial z} 
          +\frac{\partial(w \tau_{\mathrm{xz}})}{\partial x}
          +\frac{\partial(w \tau_{\mathrm{yz}})}{\partial y}
          +\frac{\partial(w \tau_{\mathrm{zz}})}{\partial z} \,.
\end{aligned}
\end{equation}
\end{document}

相关内容