# How to center align part of an equation within alignat?

I'm using the environment alignat to align my set of of equations at two different points. Now, I dot not only want to align it these two points, but also want to have everything in between these align-point centered.

currently it looks like:

x = y                    + z
a = b + blablablablablab + u


But I want to look like:

x =           y          + z
a = b + blablablablablab + u


my current code looks like:

\centering
\begin{alignat*}{2}
x &= y &+ z\\
x &= b+blablablablablab &+ u
\end{alignat*}


A possible solution with \mathmakebox from mathtools:

\documentclass[a4paper]{article}
\usepackage{mathtools}

\newlength{\mymathln}
\newcommand{\aligninside}[2]{
\settowidth{\mymathln}{#2}
\mathmakebox[\mymathln]{#1}
}

\begin{document}

\begin{alignat*}{2}
x &= \aligninside{y}{b+blablablablablab} & &+ z\\
x &= b+blablablablablab & &+ u
\end{alignat*}

\end{document}


The result:

• The spacing around the second + is wrong. Replace the second & by & & – daleif Sep 20 '13 at 11:38
• Is there a more elegant way to go about it? I'd love to do the same thing, but for me, the b+blablablablablab is ten times longer. – jvriesem Feb 11 '15 at 5:02
• @jvriesem: It depends: if the b+blablablablablab ten times longer is the same for several equations, you may want to compute the length only once in the preamble and the use that to increase the spacing. Otherwise, this solution is more flexible. – Claudio Fiandrino Feb 11 '15 at 7:17