Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

underbrace alignment fun & games

14 views
Skip to first unread message

coo...@nospamverizon.net

unread,
Jul 6, 2011, 2:06:03 PM7/6/11
to
Trying to figure out an 'elegant' way to control location/spacing of
underbraces in a multi-line equation array environment. I can achieve
'the right look' using brute force (trial and error with vertical
spacing elements in the math environment), but I'm hoping that someone
can point me to a more elegant solution. The following minimal example
shows an example of what I'm trying to do -- the first equation is 'what
it should look like', the second attempt is what it does look like
unless I embed a bunch of horizontal spacing controls. Basically, I'd
like the underbraces to be as wide as the element in the first line of
the equation, not the second (this will be clearer if you compile the
following...).

Thanks in advance...

\documentclass[11pt,letterpaper]{article}

\usepackage{amsmath}

\begin{document}

with `brute-force' horizontal spacing

\begin{align*}
\hat{S}_i &= \mu + \left(S_i-\mu\right) + \left(\hat{S}_i-S_i\right)\\
&=\mu+ \underbrace{\quad\;\delta_i\quad\;\,}_{\begin{smallmatrix}
\uparrow\;\sigma^2 \\
~\\
\text{\scriptsize{(process}}\\ \text{\scriptsize{variance)}}
\end{smallmatrix}} +
\,\underbrace{\quad\;\epsilon_i\quad\;\,}_{\begin{smallmatrix}
\uparrow\;\mbox{\scriptsize{var}}\left(\hat{S}_i|S_i\right) \\
~\\
\text{\scriptsize{(sampling}}\\ \text{\scriptsize{variance)}}
\end{smallmatrix}}
\end{align*}

without horizontal spacing

\begin{align*}
\hat{S}_i &= \mu + \left(S_i-\mu\right) + \left(\hat{S}_i-S_i\right)\\
&=\mu+ \underbrace{\delta_i}_{\begin{smallmatrix} \uparrow\;\sigma^2 \\
~\\
\text{\scriptsize{(process}}\\ \text{\scriptsize{variance)}}
\end{smallmatrix}} + \underbrace{\epsilon_i}_{\begin{smallmatrix}
\uparrow\;\mbox{\scriptsize{var}}\left(\hat{S}_i|S_i\right) \\
~\\
\text{\scriptsize{(sampling}}\\ \text{\scriptsize{variance)}}
\end{smallmatrix}}
\end{align*}

\end{document}

Enrico Gregorio

unread,
Jul 6, 2011, 2:45:11 PM7/6/11
to
<coo...@NOSPAMverizon.net> wrote:

\usepackage{calc}
\newcommand{\centerto}[2]{%
\makebox[\widthof{$\displaystyle#2$}]{$\displaystyle#1$}}


...

\begin{align*}
\hat{S}_i &= \mu + (S_i-\mu) + (\hat{S}_i-S_i)\\
&=\mu +
\underbrace{\centerto{\delta_i}{(S_i-\mu)}}
_{\begin{subarray}{c}
\uparrow\;\sigma^2\\
\text{(process}\\
\text{variance)}
\end{subarray}}
+
\underbrace{\centerto{\epsilon_i}{(\hat{S}_i-S_i)}}
_{\begin{subarray}{c}
\uparrow\;\operatorname{var}(\hat{S}_i\mid S_i)\\
\text{(sampling}\\
\text{variance)}\\
\end{subarray}}
\end{align*}

Ciao
Enrico

GL

unread,
Jul 6, 2011, 3:06:39 PM7/6/11
to
Le 06/07/2011 20:06, coo...@NOSPAMverizon.net a �crit :


You can also consider using \substrack, with \\[dimen] for spacing:

\begin{align*}
\hat S_i &= \mu + \left(S_i-\mu\right) + \left(\hat S_i-S_i\right)\\
&= \mu + \underbrace{\quad\;\delta_i\quad\;\,}_{\substack
{\uparrow\;\sigma2 \\[1ex]

\text{(process}\\ \text{variance)}}}
+
\,\underbrace{\quad\;\epsilon_i\quad\;\,}_{\substack{\uparrow\;\operatorname{var}\left(\hat
S_i\middle| S_i\right) \\

\text{{(sampling}}\\ \text{{variance)}}}}
\end{align*}

coo...@nospamverizon.net

unread,
Jul 6, 2011, 3:11:28 PM7/6/11
to
On 7/6/2011 2:45 PM, Enrico Gregorio wrote:
> <coo...@NOSPAMverizon.net> wrote:
>
>> Trying to figure out an 'elegant' way to control location/spacing of
>> underbraces in a multi-line equation array environment. I can achieve
>> 'the right look' using brute force (trial and error with vertical
>> spacing elements in the math environment), but I'm hoping that someone
>> can point me to a more elegant solution. The following minimal example
>> shows an example of what I'm trying to do -- the first equation is 'what
>> it should look like', the second attempt is what it does look like
>> unless I embed a bunch of horizontal spacing controls. Basically, I'd
>> like the underbraces to be as wide as the element in the first line of
>> the equation, not the second (this will be clearer if you compile the
>> following...).
>>
>> Thanks in advance...
>>
>> \documentclass[11pt,letterpaper]{article}
>>
>> \usepackage{amsmath}
>>
>> \begin{document}
>>
>> with `brute-force' horizontal spacing
>>
>> \begin{align*}
>> \hat{S}_i&= \mu + \left(S_i-\mu\right) + \left(\hat{S}_i-S_i\right)\\

>> &=\mu+ \underbrace{\quad\;\delta_i\quad\;\,}_{\begin{smallmatrix}
>> \uparrow\;\sigma^2 \\
>> ~\\
>> \text{\scriptsize{(process}}\\ \text{\scriptsize{variance)}}
>> \end{smallmatrix}} +
>> \,\underbrace{\quad\;\epsilon_i\quad\;\,}_{\begin{smallmatrix}
>> \uparrow\;\mbox{\scriptsize{var}}\left(\hat{S}_i|S_i\right) \\
>> ~\\
>> \text{\scriptsize{(sampling}}\\ \text{\scriptsize{variance)}}
>> \end{smallmatrix}}
>> \end{align*}
>>
>> without horizontal spacing
>>
>> \begin{align*}
>> \hat{S}_i&= \mu + \left(S_i-\mu\right) + \left(\hat{S}_i-S_i\right)\\

>> &=\mu+ \underbrace{\delta_i}_{\begin{smallmatrix} \uparrow\;\sigma^2 \\
>> ~\\
>> \text{\scriptsize{(process}}\\ \text{\scriptsize{variance)}}
>> \end{smallmatrix}} + \underbrace{\epsilon_i}_{\begin{smallmatrix}
>> \uparrow\;\mbox{\scriptsize{var}}\left(\hat{S}_i|S_i\right) \\
>> ~\\
>> \text{\scriptsize{(sampling}}\\ \text{\scriptsize{variance)}}
>> \end{smallmatrix}}
>> \end{align*}
>>
>> \end{document}
>
> \usepackage{calc}
> \newcommand{\centerto}[2]{%
> \makebox[\widthof{$\displaystyle#2$}]{$\displaystyle#1$}}
>
>
> ...
>
> \begin{align*}
> \hat{S}_i&= \mu + (S_i-\mu) + (\hat{S}_i-S_i)\\

> &=\mu +
> \underbrace{\centerto{\delta_i}{(S_i-\mu)}}
> _{\begin{subarray}{c}
> \uparrow\;\sigma^2\\
> \text{(process}\\
> \text{variance)}
> \end{subarray}}
> +
> \underbrace{\centerto{\epsilon_i}{(\hat{S}_i-S_i)}}
> _{\begin{subarray}{c}
> \uparrow\;\operatorname{var}(\hat{S}_i\mid S_i)\\
> \text{(sampling}\\
> \text{variance)}\\
> \end{subarray}}
> \end{align*}
>
> Ciao
> Enrico


Very slick -- works very well. Thank you very much!

coo...@nospamverizon.net

unread,
Jul 6, 2011, 3:11:52 PM7/6/11
to


Hmm -- looks intriguing, but I can't get it to compile.

Enrico Gregorio

unread,
Jul 6, 2011, 3:28:20 PM7/6/11
to
<coo...@NOSPAMverizon.net> wrote:

I let TeX do the measurements; with \centerto I tell it
to place the first argument in a space as wide as the
second.

For multiple line subscripts, there's "subarray", to
which you can tell the alignment.

Ciao
Enrico

Joris Pinkse

unread,
Jul 6, 2011, 3:29:55 PM7/6/11
to
On 07/06/2011 03:28 PM, Enrico Gregorio wrote:
> <coo...@NOSPAMverizon.net> wrote:
>

>> Very slick -- works very well. Thank you very much!
>
> I let TeX do the measurements; with \centerto I tell it
> to place the first argument in a space as wide as the
> second.
>
> For multiple line subscripts, there's "subarray", to
> which you can tell the alignment.
>
> Ciao
> Enrico

Presumably you can achieve much the same thing with \hphantom.

GL

unread,
Jul 6, 2011, 3:44:11 PM7/6/11
to
Le 06/07/2011 21:11, coo...@NOSPAMverizon.net a �crit :

> On 7/6/2011 3:06 PM, GL wrote:
>>
>>
>> You can also consider using \substrack, with \\[dimen] for spacing:
>>

\documentclass [a4paper]{article}
\usepackage {amsmath}
\begin{document}


\begin{align*}
\hat S_i &= \mu + \left(S_i-\mu\right) + \left(\hat S_i-S_i\right)\\
&= \mu + \underbrace{\quad\;\delta_i\quad\;\,}
_{\substack {\uparrow\;\sigma2 \\[1ex]
\text{(process}\\ \text{variance)}}}
+ \,\underbrace{\quad\;\epsilon_i\quad\;\,}
_{\substack{\uparrow\;\operatorname{var}
\left(\hat S_i\middle| S_i\right) \\
\text{{(sampling}}\\ \text{{variance)}}}}
\end{align*}

\end{document}\endinput

> Hmm -- looks intriguing, but I can't get it to compile.


This is because those crap environment from the AmS don't allow
a blank line in their body...

Regards.

Enrico Gregorio

unread,
Jul 6, 2011, 3:52:30 PM7/6/11
to
Joris Pinkse <pin...@gmail.com> wrote:

The problem is not only to leave a space, but to place an
object in the middle of it. There are other solutions, of course,
for example

\newcommand{\centerto}[2]{%
{\ooalign{$\displaystyle\hphantom{#2}$\cr
\hidewidth$\displaystyle#1$\hidewidth\cr}}}

which does not require calc, but requires to know \ooalign.
In any case TeX has to typeset #2 in order to measure its
width.

Ciao
Enrico

GL

unread,
Jul 6, 2011, 4:16:02 PM7/6/11
to
Le 06/07/2011 21:52, Enrico Gregorio a ÔøΩcrit :

Yes and what if you want to extend the mechanism to typeset :

A = ÔøΩ + .... + ..... \\
= ÔøΩ + ..... + ..... \\
= ÔøΩ + ...... + ...... \\
= ÔøΩ + ... + ... \\
|------| |------|

Is there something to align the operands ? {array} ?

Regards.

Lars Madsen

unread,
Jul 6, 2011, 4:44:02 PM7/6/11
to

alignat, though it may cost a few extra &'s and perhaps a few {}'s

Enrico Gregorio

unread,
Jul 6, 2011, 4:55:54 PM7/6/11
to
GL <goua...@gmail.com> wrote:

I'd set an \halign with a dummy last row; then I'd get at
\lastbox, dismantle it and use the measures for setting
the lengths of the braces.

Too complicated: some visual formatting is sometimes the
fastest way. Such constructions are not so frequent as
to require a general solution.

Ciao
Enrico

GL

unread,
Jul 6, 2011, 4:58:55 PM7/6/11
to
Le 06/07/2011 22:44, Lars Madsen a ÔøΩcrit :

Alignment requires & obviously... Then AmS can give the columns widths:

\documentclass [a4paper]{article}
\usepackage {amsmath}
\begin{document}\makeatletter

\def\AmScolumnwidth #1{\ifmeasuring@ #1\else
\hbox to\AmScolumn@width {\hss$#1$\hss}\fi }

\def\AmScolumn@width {\ifcase \numexpr\column@+1\maxcolumn@widths \fi }

\begin{alignat*}{6}
\hat S_i &= \mu &+ &\left(S_i-\mu\right) &+& \left(\hat S_i-S_i\right)\\
&= \mu &+ &\underbrace{\AmScolumnwidth{\delta_i}}


_{\substack {\uparrow\;\sigma2 \\[1ex]

\text{(process}\\ \the\column@
\text{variance)}}}
&+ &\underbrace{\AmScolumnwidth{\epsilon_i}}


_{\substack{\uparrow\;\operatorname{var}
\left(\hat S_i\middle| S_i\right) \\

\text{{(sampling}}\\
\text{{variance)}}}}
\end{alignat*}
\end{document}\endinput

\substack for concision but subarray would go as well.

Cheers.

GL

unread,
Jul 6, 2011, 5:01:06 PM7/6/11
to
Le 06/07/2011 22:55, Enrico Gregorio a ÔøΩcrit :

Not too complicated if one know how AmS stores its dimensions.
But too late, i've posted the solution already... might be of interest
for something else yet.

>
> Ciao
> Enrico

0 new messages