\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amsmath, amssymb}
\usepackage{soul}
\usepackage[dvipsnames]{xcolor}
\newcommand{\mathcolorbox}[2]{\colorbox{#1}{$\displaystyle #2$}}
\begin{document}
\begin{align*}
\binom n i p^i ( 1 - p )^{ n - i }
& = \frac{ n! }{ i! ( n - i )! } \, p^i \, ( 1 - p )^{ n - i } \\
& = \frac{ n! }{ \mathcolorbox{ProcessBlue}{ i! } ( n - i )! }
\left ( \frac \lambda n \right )^i
\left ( 1 - \frac \lambda n \right )^{ n - i } \\
& = \mathcolorbox{YellowGreen}{ \frac{ n! }{ n^i ( n - i )! } }
\frac{ \lambda^i }{ \mathcolorbox{ProcessBlue}{ i! } }
\frac{ \mathcolorbox{Yellow}{ \left ( 1 - \frac \lambda n \right )^n }
\to e^{ -\lambda } \text{ when } n \to +\infty }{
\left \{ \left ( 1 - \dfrac \lambda n \right )^i \right \}
\to 1 \text{ when } n \to +\infty } \\
& = \mathcolorbox{Yellow}{ e^{ -\lambda } }
\frac{ \lambda^i }{ i! }
\mathcolorbox{YellowGreen}{
\frac{ n ( n - 1 ) \cdots ( n - i + 1 ) }{ n^i } } \to 1
\text{ when } n \to +\infty \\
& = \frac{ \lambda^i }{ i! } e^{ -\lambda }
\end{align*}
\end{document}
-Edit-
First off, coloring does not mean anything in particular. Only the right-most fraction inside the red box is relevant.
As you can see, the fraction line also spans over the \to e^{ -\lambda } \text{ when } n \to +\infty
and \to 1 \text{ when } n \to +\infty
comments; instead, I only want it to cover \left ( 1 - \frac \lambda n \right )^n
and \left ( 1 - \frac \lambda n \right )^i
\frac
are centered horizontally by default. Do please clarify what you mean by "shorten the fraction line so as to include only the two of them". And, please clarify what the significance of coloring some expressions in yellow, gree, and blue may be.\frac
argument. I want to keep the comments in more or less the same position, but outside the\frac
command: these comments are the only thing that's different between numerator and denominator, so I guess taking care of them would also center the fraction arguments Other than the red box (of which you can ignore anything but the right-most fraction), coloring is not relevant\frac
component, and use\genfrac
(fromamsmath
; see the user manual) for the comments. You'll have to adjust the vertical position of the comments; that can be done with\vphantom
.\genfrac
is not (height-wise) aligned with either numerator or denominator (maybe because of coloring, which makes\frac
higher than it actually is). No matter though, I can settle for @Mico's solution