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: