# \underbrace and notes in the center environment

Here is a little snippet of my code:

\begin{center}
$\small \displaystyle \underbrace{(- \frac{1}{2})^0}_{\text{1st term, j = 0}} + \underbrace{(- \frac{1}{2})^1}_{\text{2nd term, j = 1}} + \underbrace{(- \frac{1}{2})^2}_ {\text{3rd term, j = 2}} + ~...+ \underbrace{(- \frac{1}{2})^k}_{\text{kth term, 2nd to \linebreak last term, j = k}} + \underbrace{(- \frac{1}{2})^{k+1}}_{\text{(k+1)th term, last in the sum}}$
\end{center}


and this is the output

I would like this to be on one line, but have the notes underneath the last two terms split into two. How might I do this?

-
So do you want two lines in the notes below the fractions? Not two lines for the whole expression? Also, use  to center a math expression. – Sigur Dec 31 '13 at 16:52
I would like to two lines in the notes below the fractions. How does using [ ] compare to using center? What would I have to change? – Mack Dec 31 '13 at 16:54
@Mack Don't use center for displaying equations, but $...$ – egreg Dec 31 '13 at 17:19

this differs only slightly from the answer by Sigur, but i think it's worth some small adjustments.

\documentclass{article}
\usepackage{mathtools}
\begin{document}
\begingroup
\small
$\displaystyle \underbrace{\left(-\frac{1}{2}\right)^0}_{\substack{\text{1st term,}\\ j = 0}} + \underbrace{\left(-\frac{1}{2}\right)^1}_{\substack{\text{2nd term,}\\ j = 1}} + \underbrace{\left(-\frac{1}{2}\right)^2} _{\substack{\text{3rd term,}\\ j = 2}} + \ \cdots\ + \underbrace{\left(-\frac{1}{2}\right)^k} _{\substack{\text{\ \ kth term,\ \ }\\ \mathclap{\text{2nd to last term,}}\\ j = k}} + \underbrace{\left(-\frac{1}{2}\right)^{k+1\mkern-20mu}} _{\substack{\text{(k{+}1)th term,}\\ \text{ last in the sum }}}$
\endgroup

\end{document}


here are the differences:

• to narrow the next-to-last term (thus reducing the space around the final plus), the widest line in the substack was "compressed" using \mathclap (requires mathtools), and spaces were added to the first line to adjust so that the notations on the last two terms don't overlap. (shortening this phrase is probably a better approach, actually, but that might not always be feasible.)

• negative space was added to the end of the superscript on the last term, allowing it to hang over the brace, resulting in a brace closer in size to the others.

• space was added (inside the \text) to the second line of the substack on the last term to further improve the spacing between the last two terms.

• in the first line of the notation on the last term, braces were put around the {+} so that the spacing within k+1 is optically comparable to the spacing in the superscript. (it should probably be \$(k+1)st, but let's not quibble.)

egreg's use of a macro refinement in Sigur's answer is a good idea that would work here too.

-

As suggested by @egreg, using \substack{} you can insert multiple lines. Also, the font size is automatically adjusted.

Note some extra spaces \ \around the \cdots (requested by @Thruston).

\documentclass{article}
\usepackage{amsmath}

\begin{document}
$\underbrace{\left( -\frac{1}{2}\right)^0}_{\substack{ \text{1st term,}\\ j = 0}} + \underbrace{\left( -\frac{1}{2}\right)^1}_{\substack{\text{2nd term,}\\ j = 1}} + \underbrace{\left( -\frac{1}{2}\right)^2}_{\substack{\text{3rd term,}\\ j = 2}} + \ \cdots \ + \underbrace{\left( -\frac{1}{2}\right)^k}_{\substack{\text{kth term,}\\ \text{2nd to last term,}\\ j = k} } + \underbrace{\left( -\frac{1}{2}\right)^{k+1}}_{\substack{\text{(k+1)th term,}\\ \text{last in the sum}} }$
\end{document}


A refinement for using less keystrokes and minimize the chance of errors:

\documentclass{article}
\usepackage{amsmath}

\begin{document}
$% Define a shortcut macro just for this display; % use \left and \right instead of \Bigl and \Bigr % if you feel these are too small \newcommand{\myterm}[2]{% \underbrace{\Bigl(-\frac{1}{2}\Bigr)^{#1}}_{\substack{#2}}% } \myterm{0}{\text{1st term,} \\ j=0}+ \myterm{1}{\text{2nd term,} \\ j=1}+ \myterm{2}{\text{3rd term,} \\ j=2}+ \;\cdots\;+ % some space around the dots \myterm{k}{\text{kth term,} \\ \text{2nd to last,} \\ j=k}+ \myterm{k+1}{\text{(k+1)th term,} \\ \text{last in the sum}}$
\end{document}


-
I'd use \substack (with \text inside) instead of a tabular – egreg Dec 31 '13 at 16:59
This is precisely what I was looking for. Thank you, Sigur. – Mack Dec 31 '13 at 17:02
@egreg, well remembered. I'll edit with your suggestion. – Sigur Dec 31 '13 at 17:02
@Sigur and some extra space around the cdots? – Thruston Dec 31 '13 at 17:03
@Sigur I added a possibly better solution; it's basically the same as yours, the local macro avoids many keystrokes. – egreg Dec 31 '13 at 17:18