0

Any ideas how to make these description in the last line prettier without losing information? I mean it will be fine the way it is, but it is quite suprising what nice things you sometimes are unaware of (like "for" loops in tikz).

\documentclass{article}
\usepackage{mathtools}
\begin{document}
\begin{align*}
   \bar{X}_n&=\frac{1}{n}\sum_{i=1}^n X_i 
    = \frac{n-1}{n}\frac{1}{n-1}\sum_{i=1}^{n-1}X_i +\frac{1}{n}X_n\\
    &=\left(1-\frac{1}{n}\right)\bar{X}_{n-1}+\frac{1}{n}X_n \\
    &= \bar{X}_{n-1} 
    + \underbracket[1pt]{\frac{1}{n}}_{\text{``learning rate''}}
    \underbracket[1pt]{(X_n - \bar{X}_{n-1})}_{\text{``direction''}}
\end{align*}
\end{document}

enter image description here

Felix B.
  • 387

2 Answers2

4

I don't know if this improves things but a few ideas, I removed \left\right and chose a slightly smaller \Bigl\Bigr, I replaced the square under bracket by a brace and added a phantom so they are both at the same level, and finally shrunk the text and added some negative space to close up that last term a bit,

enter image description here

\documentclass{article}
\usepackage{mathtools}
\begin{document}
\begin{align*}
   \bar{X}_n&=\frac{1}{n}\sum_{i=1}^n X_i 
    = \frac{n-1}{n}\frac{1}{n-1}\sum_{i=1}^{n-1}X_i +\frac{1}{n}X_n\\
    &=\Bigl(1-\frac{1}{n}\Bigr)\bar{X}_{n-1}+\frac{1}{n}X_n \\
    &= \bar{X}_{n-1} 
    + \hspace{-1em}
    \underbrace{\frac{1}{n}}_{\scriptscriptstyle\text{``learning rate''}} \hspace{-.5em}
    \underbrace{\vphantom{\frac{1}{n}}(X_n - \bar{X}_{n-1})}_{\scriptscriptstyle\text{``direction''}}
\end{align*}
\end{document}
David Carlisle
  • 757,742
3

I propose this: a wide bar over the X with an adhoc command (alternatively there is a widebar package on this site), medium-size fractions from nccmath for fractionary coefficients, and playing with \clap, since you load mathtools for the text of the left \underbracket:

\documentclass{article}
\usepackage{mathtools, nccmath}
\newcommand{\mybarX}{\mkern3.5mu\overline{\mkern-3.5mu X\mkern-1mu}}

\begin{document}

\begin{align*}
    \mybarX_n&=\mfrac{1}{n}\sum_{i=1}^n X_i
    = \mfrac{n-1}{n}\mfrac{1}{n-1}\sum_{i=1}^{n-1}X_i +\mfrac{1}{n}X_n\\
    &=\left(1-\mfrac{1}{n}\right)\mybarX_{n-1}+\mfrac{1}{n}X_n \\
    &= \mybarX_{n-1}
    + \underbracket[0.6pt][1.3ex]{\mfrac{1}{n}}_{\strut\text{\clap{``learning rate''}}}
    \underbracket[0.6pt]{(X_n - \mybarX_{n-1})}_{\text{``direction''}}
\end{align*}

\end{document} 

enter image description here

Bernard
  • 271,350
  • yes the medium fractions are probably good here, I'd tried tfrac in my answer but that seemed too small here so I left them as default display frac. +1 – David Carlisle Mar 19 '19 at 21:19
  • what does \strut do? – Felix B. Mar 19 '19 at 21:24
  • I agree \tfrac looks often much petty w.r.t. the context. I didn't like \dfrac here, because the fraction is taller than the Σ symbol. – Bernard Mar 19 '19 at 21:24
  • 1
    \strut adds an invisible small rule, to increase the distance of the text from the underbracket, so the two texts do not overlap. – Bernard Mar 19 '19 at 21:26
  • https://tex.stackexchange.com/questions/16337/can-i-get-a-widebar-without-using-the-mathabx-package/60253#60253 this one? – Felix B. Mar 19 '19 at 21:33
  • It's precisely this one, yes, that I didn't have time to look for. A very useful non-official package (better than \overline for this usage, because it takes into account the italic slant of the font). – Bernard Mar 19 '19 at 22:06