Question: I have an equation in which I want to use underbrace , but the braces appear in different heights since one term is longer than the other. Here is an example:

```
\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{physics}
\begin{document} 
  \begin{align}
    \underbrace{-\frac{1}{M}\vec{p}{\partial\vec{p}}\frac{\partial\mathcal{P}}{\partial\vec{x}}}_{\frac{\partial\mathcal{H}} {\partial\vec{p}}}+\underbrace{\mathcal{U}'}_{\frac{\partial\mathcal{H}}{\partial\vec{x}}}\mathcal{P}
  \end{align}
 \end{document}

```

I tried using vphantom, but then my equation got distorted noticeably. How can I fix this ? Thank you in advance.

Answer: 
I see no problem if I add a `\vphantom` for the bigger object in the first term.

I added a few items:

1. braces around the `\underbrace` constructs, to get good spacing when operators are involved;
2. a couple of thin spaces after `\vec{...}` constructs in order to avoid clashes;
3. removed the call to `physics`, which you're not using and, in my opinion, should not be used because of several weaknesses.

```
\documentclass[12pt]{article}
\usepackage{amsmath}

\begin{document} 

\begin{align}
{\underbrace{
  -\frac{1}{M}\vec{p}\,\partial\vec{p}\,\frac{\partial\mathcal{P}}{\partial\vec{x}}
}_{\frac{\partial\mathcal{H}}{\partial\vec{p}}}}
+
{\underbrace{
  \vphantom{\frac{\partial\mathcal{P}}{\partial\vec{x}}}
  \mathcal{U}'
}_{\frac{\partial\mathcal{H}}{\partial\vec{x}}}}
\end{align}

\end{document}

```

[![enter image description here](https://i.stack.imgur.com/AMmvX.png)](https://i.stack.imgur.com/AMmvX.png)
As you can see, 

```
\vphantom{\frac{\partial\mathcal{P}}{\partial\vec x}}

```

should work.

[![enter image description here](https://i.stack.imgur.com/3vOqe.png)](https://i.stack.imgur.com/3vOqe.png)

**MWE**

```
\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{physics}
\begin{document} 
  \begin{align}
    \underbrace{-\frac{1}{M}\vec{p}{\partial\vec{p}}\frac{\partial\mathcal{P}}{\partial\vec{x}}}_{\frac{\partial\mathcal{H}} {\partial\vec{p}}}+\underbrace{\vphantom{\frac{\partial\mathcal{P}}{\partial\vec x}}\mathcal{U}'}_{\frac{\partial\mathcal{H}}{\partial\vec{x}}}
  \end{align}
 \end{document}

```

[![enter image description here](https://i.stack.imgur.com/dvGR8.png)](https://i.stack.imgur.com/dvGR8.png)