# underbraces inside array

• Jan 22nd 2008, 12:39 AM
johny
underbraces inside array
Hi,

I have the following expression:

$\displaystyle \begin{array}{cclclclclcl} = & & 2^{k-2} \\ & + & 2^{k-3} & + & 2^{k-3} \\ & + & 2^{k-4} & + & 2^{k-4} & + & 2^{k-4} \\ & \vdots \\ & + & 2^1 & + & 2^1 & + & \dots & + & 2^1 \\ & + & 2^0 & + & 2^0 & + & \dots & + & 2^0 & + & 2^0 \\ \end{array}$

It is set inside an array because of the + alignment. I would like to add underbraces under the two bottom rows, such as this:

$\displaystyle + \quad \underbrace{2^1 \quad + \quad 2^1 \quad + \quad \dots \quad + \quad 2^1}_{k-2}$
$\displaystyle + \quad \underbrace{2^0 \quad + \quad 2^0 \quad + \quad \dots \quad + \quad 2^0 \quad + \quad 2^0}_{k-1}$

However, I would still like to retain the vertical alignment of all the + signs in all rows, so I need to somehow put these underbraces inside the array. (Or use array inside an array, but I can't figure exactly how.)

Do you know any way to do this? Thanks!
• Jan 22nd 2008, 12:13 PM
earboth
Hello,

maybe this reply http://www.mathhelpforum.com/math-help/94284-post2.html helps a little bit further.
• Jan 22nd 2008, 12:19 PM
johny
Quote:

Originally Posted by earboth
Hello,

maybe this reply http://www.mathhelpforum.com/math-help/94284-post2.html helps a little bit further.

It doesn't :)

I could do the bottom brace that way, but there would still be a problem with the inner one.

Also, I could put all the stuff above the inner brace into an array and then put the brace under this array, and the whole thing would be in a bigger array with the second brace under itself, but one problem still remains - the +'s in the bottom line (which is outside the inner array, but inside the outer one) would not be aligned with the +'s in the inner array (which they are out of).
• Jan 25th 2008, 05:38 AM
Krizalid

$\displaystyle \begin{split} &= 2^{k-2} \\ & \quad + 2^{k-3} + 2^{k-3} \\ & \quad+ 2^{k-4} + 2^{k-4} + 2^{k-4} \\ &\quad \quad \vdots \\ & \quad + \underbrace{2^1 + 2^1 + \cdots + 2^1}_{k-2} \\ & \quad + \underbrace{2^0 + 2^0 + \cdots + 2^0 + 2^0}_{k-1}. \end{split}$

¿?
• Jan 25th 2008, 05:39 PM
JaneBennet
$\displaystyle \begin{array}{ccl} = & {} & 2^{k-2}\\ {} & + & 2^{k-3}\ +\ 2^{k-3}\\ {} & + & 2^{k-4}\ +\ 2^{k-4}\ +\ 2^{k-4}\\ {} & {} & \vdots\\ {} & + & \underbrace{2^1\quad\;+\ 2^1\quad\;+\ \ldots\ +\ 2^1}_{k-2}\\\\ {} & + & \underbrace{2^0\quad\;+\ 2^0\quad\;+\ \ldots\ +\ 2^0\ +\ 2^0}_{k-1} \end{array}$
• Jan 25th 2008, 11:34 PM
johny
Quote:

Originally Posted by Krizalid

$\displaystyle \begin{split} &= 2^{k-2} \\ & \quad + 2^{k-3} + 2^{k-3} \\ & \quad+ 2^{k-4} + 2^{k-4} + 2^{k-4} \\ &\quad \quad \vdots \\ & \quad + \underbrace{2^1 + 2^1 + \cdots + 2^1}_{k-2} \\ & \quad + \underbrace{2^0 + 2^0 + \cdots + 2^0 + 2^0}_{k-1}. \end{split}$

¿?

Thanks, but it doesn't keep the vertical alignment of +'s, so not exactly what I needed.

Quote:

Originally Posted by JaneBennet
$\displaystyle \begin{array}{ccl} = & {} & 2^{k-2}\\ {} & + & 2^{k-3}\ +\ 2^{k-3}\\ {} & + & 2^{k-4}\ +\ 2^{k-4}\ +\ 2^{k-4}\\ {} & {} & \vdots\\ {} & + & \underbrace{2^1\quad\;+\ 2^1\quad\;+\ \ldots\ +\ 2^1}_{k-2}\\\\ {} & + & \underbrace{2^0\quad\;+\ 2^0\quad\;+\ \ldots\ +\ 2^0\ +\ 2^0}_{k-1} \end{array}$

Thanks, this looks pretty much like what I needed - but as I understand it, you just approximated the spaces to keep the alignment, so if I add/change something, I would have to approximate and change the spaces in all rows, so it is kind of unpractical if I want to use it more often. Also, I think the alignment is not 100% precise.
• Jan 28th 2008, 11:36 AM
Opalg
Quote:

Originally Posted by johny
Thanks, this looks pretty much like what I needed - but as I understand it, you just approximated the spaces to keep the alignment, so if I add/change something, I would have to approximate and change the spaces in all rows, so it is kind of unpractical if I want to use it more often. Also, I think the alignment is not 100% precise.

If you really want 100% precise alignment then you can use TeX's \rlap and \hphantom routines to write a superscript 1 that takes up exactly the same amount of space as k–4. The input looks like this:

Code:

\begin{array}{cl} = & \hphantom{{}+{}}  2^{k-2}\\ &{}  +  2^{k-3} + 2^{k-3}\\ &{} +  2^{k-4} + 2^{k-4} + 2^{k-4}\\ & \hphantom{{}+{}} \vdots\\ &{} +  \underbrace{2^{\rlap{$\scriptstyle1$}\hphantom{k-4}} + 2^{\rlap{$\scriptstyle1$}\hphantom{k-4}} + \ldots + 2^1}_{k-2}\vspace{.5ex}\\ &{} +  \underbrace{2^{\rlap{$\scriptstyle0$}\hphantom{k-4}} + 2^{\rlap{$\scriptstyle0$}\hphantom{k-4}} + \ldots + 2^0 + 2^0}_{k-1} \end{array}
I can't show the complete output here, because the LaTeX string is too long for the MathHelpForum's compiler to accept. But it works nicely with the TeX program on my computer. If I leave out a couple of lines to bring it down to MathHelpForum's 400-character limit then it looks like this:

$\displaystyle \begin{array}{cl} = & \hphantom{{}+{}} 2^{k-2}\\ &{} + 2^{k-4} + 2^{k-4} + 2^{k-4}\\ &{} + \underbrace{2^{\rlap{$\scriptstyle1$}\hphantom{k-4}} + 2^{\rlap{$\scriptstyle1$}\hphantom{k-4}} + \ldots + 2^1}_{k-2}\vspace{.5ex}\\ &{} + \underbrace{2^{\rlap{$\scriptstyle0$}\hphantom{k-4}} + 2^{\rlap{$\scriptstyle0$}\hphantom{k-4}} + \ldots + 2^0 + 2^0}_{k-1} \end{array}$