3

I would like to present an equation in the following manner:

Desired Energy Equation Alignment

However, utilising the amsmath package, this is the best I can get:

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

I would like to retain the equation label, albeit vertically centered across the equation, as opposed to underneath the last line. Any suggestions would be appreciated.

3 Answers 3

4

I'd use split and vertically align all the + signs. A local command easily does the job, and \pder vastly simplifies the input.

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

enter image description here

3

...just shifted the alignment within the aligned environment:

enter image description here

\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}
1
  • Because of the better alignment of the + signs at the beginning of the lines, I would write \phantom{={}} instead of \phantom{=}. Sep 1 at 7:26
1

In addition to shifting the alignment point in the first row to the left, you may want to rearrange the additive terms on the RHS so that it becomes immediately clear that 15 of the 17 terms can be arranged into 5 groups of 3 terms each. A side effect of this change is that you can get by with just 4 rows, rather than 5 rows, for the entire expression.

enter image description here

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .