# Multiple equations and underbrace environment

I would like to have the same result that the figure below (with others variables of course): I tried this code and it worked well, but for me it is not the right way to do because I need the numbering for each equation as it is possible to have with an align environment. The code I used is as follows and as you can see, the code is too huge. I was wondering if it is possible to reduce it to an align environment or another simple way to work with \underbrace {}? ..

\documentclass{article}
\usepackage{amsmath}
\usepackage{mathtools}

\begin{document}
$\underbrace{ \begin{array}{c} z_1 \\[0.2cm] z_2 \\[0.2cm] z_3 \\[0.2cm] z_4 \end{array}}_\text{Measurements} \begin{array}{c} = \\[0.2cm] = \\[0.2cm] = \\[0.2cm] = \end{array} \underbrace{ \begin{array}{c} h_1\left(x_1, x_2, x_3, x_4\right) \\[0.2cm] h_2\left(x_1, x_2, x_3, x_4\right) \\[0.2cm] h_3\left(x_1, x_2, x_3, x_4\right) \\[0.2cm] h_4\left(x_1, x_2, x_3, x_4\right) \end{array}}_\text{True values from system model} \begin{array}{c} + \\[0.2cm] + \\[0.2cm] + \\[0.2cm] + \end{array} \underbrace{ \begin{array}{c} e_1 \\[0.2cm] e_2 \\[0.2cm] e_3 \\[0.2cm] e_4 \end{array}}_\text{Errors}$
\end{document}


I'm not really sure either of the solutions are really satisfying; I'd probably write outside the alignment the meaning of the symbols. Anyway, here's it:

\documentclass{article}
\usepackage{amsmath}
\usepackage{mathtools,calc}

% for the align solution
\newcommand{\fakeunderbrace}{%
\mathmakebox[\widthof{$\underbrace{#3}_{#1}$}]{\;#2}%
}
\newcommand{\fuba}{%
}
\newcommand{\fubb}{%
\fakeunderbrace{\substack{\text{True values from}\\\text{system model}}}
{#1}{\,h_4(x_1, x_2, x_3, x_4)\,}%
}
\newcommand{\fubc}{%
}

% for the alignat solution
\newcommand{\fw}{\mathmakebox[\widthof{$#1$}]{#2}}
\newcommand{\fwa}{\fw{\substack{\text{Measurements}}}{#1}}
\newcommand{\fwc}{\fw{\substack{\text{Errors}}}{#1}}

\begin{document}
\begin{align}
\fuba{z_1} &= \fubb{h_1(x_1, x_2, x_3, x_4)} + \fubc{e_1} \\
\fuba{z_2} &= \fubb{h_2(x_1, x_2, x_3, x_4)} + \fubc{e_2} \\
\fuba{z_3} &= \fubb{h_3(x_1, x_2, x_3, x_4)} + \fubc{e_3} \\
\fuba{z_4} &= \fubb{h_4(x_1, x_2, x_3, x_4)} + \fubc{e_4} \\[-.8\baselineskip]
\underbrace{\mathmakebox[\widthof{$h_1(x_1, x_2, x_3, x_4)$}]{}}%
_{\substack{\text{True values from}\\\text{system model}}}
\end{align}

\begin{alignat}{2}
\substack{\text{Measurements}}
& \hphantom{{}={}}
\fwb{\substack{\text{True values from}\\\text{system model}}}
&& \hphantom{{}+{}}
\fwc{\substack{\text{Errors}}} \nonumber \\
\fwa{z_1} &= \fwb{h_1(x_1, x_2, x_3, x_4)} &&+ \fwc{e_1} \\
\fwa{z_2} &= \fwb{h_2(x_1, x_2, x_3, x_4)} &&+ \fwc{e_2} \\
\fwa{z_3} &= \fwb{h_3(x_1, x_2, x_3, x_4)} &&+ \fwc{e_3} \\
\fwa{z_4} &= \fwb{h_4(x_1, x_2, x_3, x_4)} &&+ \fwc{e_4}
\end{alignat}

\end{document} • Could you explain the different \newcommand for align solution. I don't know how is it worked exactly ? – yond4im Jul 26 '14 at 11:49
• @yond4im I first define a “generic” command to make a box that's as wide as the underbrace for #3, with subscript #1, containing #2, centered. Then I define shorthands for each column, in order not to clobber the code. – egreg Jul 26 '14 at 12:33

Here is a slightly less-calculated way, but it works: \documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{alignat}{3}
z_1\qquad &= h_1\bigl(x_1, x_2, x_3, x_4\bigr) && + \enspace e_1 \\
z_2\qquad &= h_2\bigl(x_1, x_2, x_3, x_4\bigr) && + \enspace e_2 \\
z_3\qquad &= h_3\bigl(x_1, x_2, x_3, x_4\bigr) && + \enspace e_3 \\
z_4\qquad &= h_4\bigl(x_1, x_2, x_3, x_4\bigr) && + \enspace e_4 \\[-.5\normalbaselineskip]
\underbrace{\hphantom{zzzzzzz}}_{\text{Measurements}} &
\phantom{{}=}\underbrace{\hphantom{h_4\bigl(x_1, x_2, x_3, x_4\bigr)}}_{\text{\shortstack{True values from \\ system model}}} &&
\phantom{+}\underbrace{\hphantom{eeeeee}}_{\text{Errors}} \nonumber
\end{alignat}

\end{document}