I want to achieve the following picture:
What I have tried so far:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
\begin{matrix}
\phantom{(n+{}}2^3-1^3\phantom{{}-1)^3}&=&3\times1^2&+&3\times1&+&1\\
\phantom{(n+{}}3^3-2^3\phantom{{}-1)^3}&=&3\times2^2&+&3\times2&+&1\\
\phantom{(n+{}}4^3-3^3\phantom{{}-1)^3}&=&3\times3^2&+&3\times3&+&1\\
\phantom{(n+{}}\vdots\phantom{{}-{}}\vdots\phantom{{}-1)^3}&&\vdots&&\vdots&&\vdots\\
\phantom{(n+{}}n^3-(n-1)^3&=&3(n-1)^2&+&3(n-1)&+&1\\
(n+1)^3-n^3\phantom{{{}^3}-1)^3}&=&3n^2&+&3n&+&1\\\hline
(n+1)^3-1^3\phantom{{{}^3}-1)^3}&=&3(\sum_{i=1}^ni^2)&+&3(\sum_{i=1}^ni)&+&n\\
&=&3(\sum_{i=1}^ni^2)&+&\dfrac{3n(n+1)}{2}&+&n\\
\end{matrix}
\]
\end{document}
I think it's pretty well, however if we zoom on n^3-(n-1)^3
and (n+1)^3-n^3
we can see they are not perfectly aligned:
I can't imagine another expr
in \phantom{expr}
than the one I put in the code:
- Before
-
sign: Since the longest expression is(n+1)^3
and I haven^3
, the space that compensates I think it should be(n+{}
so\phantom{(n+{}}
. - After
-
sign: Since the longest expression is(n-1)^3
and I haven^3
, the space that compensates I think it should be{{}^3}-1)^3
so\phantom{{{}^3}-1)^3}
.
What should be the 2 expressions that must go in \phantom
?
P.S. I know I could go for adding &
before and after -
sign, but I think it is a better approach using \phantom
. What do you think?
&
is more natural than faking alignment with\phantom