Text in underbrace is too long and alignment of equation is changing

\begin{equation}
\begin{aligned}
\label{mat:mom}
\rho g\textsubscript{x} &- \frac{\partial p}{\partial x} + \mu(\frac{\partial^2 u}{\partial x^2} +  \frac{\partial^2 u}{\partial y^2} + \frac{\partial^2 u}{\partial z^2}) &=\quad \rho\frac{\partial u}{\partial t} \\
\underbrace{\rho g\textsubscript{z}}_{Body forces per unit volume} &- \underbrace{\frac{\partial p}{\partial z}}_{Pressure forces per unit volume} + \underbrace{\mu(\frac{\partial^2 w}{\partial x^2} +  \frac{\partial^2 w}{\partial y^2} + \frac{\partial^2 w}{\partial z^2})}_{Viscous forces per unit volume} &= \underbrace{\quad \rho\frac{\partial w}{\partial t}}_{Inertial forces per unit volume}
\end{aligned}
\end{equation}

The text in underbrace is tto long and it causes the equations to be misaligned.How to split the text in underbraces to two lines. i tried using \\but it dooesnt seem to help.

• \textsubscript{x} should be _{x}. Never use \textsubscript in math mode. Jun 24 '18 at 15:54

I'd first avoid repeating “forces per unit volume”. Diagrams like these require a bit of manual work in order to get proper alignment.

\documentclass{article}
\usepackage{amsmath,array}

\newcommand{\textunderbrace}{{%
\underbrace{#1}_{\text{#2}}
}}

\begin{document}

\begin{equation}\label{mat:mom}
\setlength{\arraycolsep}{0pt}
\newcolumntype{e}{>{\displaystyle}c}
\newcolumntype{o}{>{{}}c<{{}}}
\newcommand{\vs}{\vphantom{\biggl(\frac{\partial^2 w}{\partial x^2}}}
\textunderbrace{
\renewcommand{\arraystretch}{2.5}
\begin{array}{ e o e o e o e }
\rho g_{x}
&-& \frac{\partial p}{\partial x}
&+& \mu\biggl(\frac{\partial^2 u}{\partial x^2}
+  \frac{\partial^2 u}{\partial y^2}
+  \frac{\partial^2 u}{\partial z^2}\biggr)
&=& \rho\frac{\partial u}{\partial t} \\
\textunderbrace{\rho g_{z}\vs}{Body}
&-& \textunderbrace{\frac{\partial p}{\partial z}\vs}{\makebox[0pt]{Pressure}}
&+& \textunderbrace{\mu\biggl(\frac{\partial^2 w}{\partial x^2}
+  \frac{\partial^2 w}{\partial y^2}
+  \frac{\partial^2 w}{\partial z^2}\biggr)}{Viscous}
&=& \textunderbrace{\rho\frac{\partial w}{\partial t}\vs}{\makebox[0pt]{Inertial}}
\end{array}
}{forces per unit volume}
\end{equation}

\end{document} A variant with stackengine. I loaded esdiff for a simpler typing of partial derivatives:

\documentclass{article}
\usepackage[a4paper]{geometry}
\usepackage[usestackEOL]{stackengine}
\usepackage{mathtools}
\usepackage{esdiff}
\newcommand{\textub}{\scriptsize\Shortunderstack{#1}}

\begin{document}

\begin{equation}
\begin{alignedat}{3}
\label{mat:mom}
\rho g\textsubscript{x} &- \diffp{p}{x} & & + \mu\biggl(\diffp{u}{x} + \diffp{u}{y} + \diffp{u}{z}\biggr) & & =\rho\diffp{u}{t} \\
\underbrace{\rho g\textsubscript{z}}_{\textub{Body\\ forces}} &- \underbrace{\diffp{p}{z}}_{\clap{\textub{Pressure\\ forces}}} & & + \underbrace{\mu\biggl(\diffp{w}{x} + \diffp{w}{y} + \diffp{w}{z}\biggr)}_{\textub{Viscous forces}} & &= \underbrace{\rho\diffp{w}{t}}_{\clap{\textub{Inertial forces}}}\\
& & & \rlap{\scriptsize per unit volume}
\end{alignedat}
\end{equation}

\end{document} You should use \text for the text below the under braces, this combined with some \raisebox and \mathllap and \mathrlap (provided by mathtools) you can get something like the following. This however doesn't look good...

Another way would be to mark the code with some counter and reference those marks to explain the code. I used some \raiseboxes there, for better vertical alignment (the encircled letters where too close to the tips of the braces).

Also you should not use \textsubscript in math mode, for single letter indices (even for multiple single letters), instead use _{<indices>} and for a full word or an abbreviation use _{\text{<index>}}.

And you could consider using \left, \right braces (or manual sizing with stuff like \big().

\documentclass[]{article}

\usepackage{mathtools}

% Using \mylabel to hide the \label from amsmath
\let\mylabel\label
\newcounter{eqannotate}[equation]
\renewcommand*\theeqannotate{\textcircled{\footnotesize\alph{eqannotate}}}
\newcommand*\eqannotate[]
{%
\hbox
{%
\begingroup
\refstepcounter{eqannotate}%
\if\relax\detokenize{#1}\relax
\else
\mylabel{#1}%
\fi
\endgroup
\theeqannotate
}%
}

\begin{document}

\begin{equation}
\begin{aligned}
\label{mat:mom}
\rho g_{x}
&- \frac{\partial p}{\partial x}
+ \mu\left(\frac{\partial^2 u}{\partial x^2} + \frac{\partial^2
u}{\partial y^2} + \frac{\partial^2 u}{\partial z^2}\right)
&= \rho\frac{\partial u}{\partial t} \\
\underbrace{\rho g_{z}}_{\mathllap{\text{Body forces per unit volume}}}
&- \underbrace{\frac{\partial p}{\partial z}}
_{\mathclap{\text{\raisebox{-1.5ex}{Pressure forces per unit volume}}}}
+ \underbrace{\mu\left(\frac{\partial^2 w}{\partial x^2} +  \frac{\partial^2
w}{\partial y^2} + \frac{\partial^2 w}{\partial z^2}\right)}
_{\hspace{-2em}\mathrlap{\text{\raisebox{-2ex}{Viscous forces per unit
volume}}}}
&= \underbrace{\rho\frac{\partial w}{\partial t}}
_{\mathrlap{\text{Inertial forces per unit volume}}}
\end{aligned}
\end{equation}

\begin{equation}
\begin{aligned}
\label{mat:mom2}
\rho g_{x}
&- \frac{\partial p}{\partial x}
+ \mu\left(\frac{\partial^2 u}{\partial x^2} +  \frac{\partial^2
u}{\partial y^2} + \frac{\partial^2 u}{\partial z^2}\right)
&= \rho\frac{\partial u}{\partial t} \\
\underbrace{\rho g_{z}}_{\raisebox{-.5ex}{\eqannotate[an:first]}}
&- \underbrace{\frac{\partial p}{\partial
z}}_{\raisebox{-.5ex}{\eqannotate[an:sec]}}
+ \underbrace{\mu\left(\frac{\partial^2 w}{\partial x^2} +
\frac{\partial^2 w}{\partial y^2} + \frac{\partial^2 w}{\partial
z^2}\right)}_{\raisebox{-.5ex}{\eqannotate[an:third]}}
&= \underbrace{\rho\frac{\partial w}{\partial
t}}_{\raisebox{-.5ex}{\eqannotate[an:fourth]}}
\end{aligned}
\end{equation}
With
\ref{an:first} being the body forces per unit volume,
\ref{an:sec} the pressure forces per unit volume,
\ref{an:third} the viscous forces per unit volume,
and \ref{an:fourth} the inertial forces per unit volume.

\end{document} • The second option looks good! But why do you need to hide \label? Jun 24 '18 at 14:34
• @SirReal just try to use \label instead of \mylabel in \eqannotate and you'll see. amsmath environments seem to parse the used \labels. Jun 24 '18 at 16:36
• You might take a look e.g. here for better looking alternatives to \textcircled, if you want to, or change the definition of \theeqannotate completely to match your tastes. Jun 24 '18 at 16:38