目标:尽可能清晰地显示扩展过程,这样我们就不会误读扩展后的长表达式相应项的系数。
\documentclass[preview,border=12pt]{standalone}
\usepackage{mathtools}
\begin{document}
\abovedisplayskip=0pt\relax% this line is not used in the production
\begin{align*}
(x^2 +x +1)(3x^2 -2x +1)(x^2 +5x -3)
&= \!
\begin{alignedat}[t]{4}
(x^2 +x +1)(3x^4 &&{}+15x^3 &&{}-9x^2 \\
&&{}-2x^3 &&{}-10x^2 &&{}+6x \\
&& &&{}+x^2 &&{}+5x &&{}-3 )
\end{alignedat}\\
&= (x^2 +x +1)(3x^4 +13x^3 -18x^2 +11x -3)\\
&= \!
\begin{alignedat}[t]{7}
3x^6 &&{}+13x^5 &&{}-18x^4 &&{}+11x^3 &&{}-3x^2 \\
&&{}+3x^5 &&{}+13x^4 &&{}-18x^3 &&{}+11x^2 &&{}-3x \\
&& &&{}+3x^4 &&{}+13x^3 &&{}-18x^2 &&{}+11x &&{}-3
\end{alignedat}\\
&= 3x^6 +16x^5 -2x^4 +6x^3 -10x^2 +8x -3
\end{align*}
\end{document}
问题:有没有更好的方法?
答案1
我使用了右对齐,这样指数就可以对齐了。就我个人而言,我也会对齐加号和减号,但这更接近原始格式。
\documentclass{article}
\usepackage{mathtools}
\newlength{\offset}% array row spacing
\setlength{\offset}{\arraystretch\ht\strutbox}
\addtolength{\offset}{\arraystretch\dp\strutbox}
\settowidth{\arraycolsep}{$\,$}
\begin{document}
\begin{align*}
P(x) &= (x^2 +x +1)(3x^2 -2x +1)(x^2 +5x -3) \\
&= (x^2 +x +1)
\raisebox{-\offset}{$\hspace{-\arraycolsep}%
\begin{array}{rrrrr}\displaystyle
(3x^4 &+\,15x^3 &-\,9 x^2 \\
&-\,2x^3 &-\,10x^2 &+\,6x \\
& &+\,x^2 &+\,5x &-\,3)
\end{array}$} \\
&= (x^2 +x +1)(3x^4 +13x^3 -18x^2 +11x -3)\\
&= \raisebox{-\offset}{$\hspace{-\arraycolsep}%
\begin{array}{rrrrrrr}\displaystyle
3x^6 &+\,13x^5 &-\,18x^4 &+\,11x^3 &-\,3x^2 \\
&+\,3x^5 &+\,13x^4 &-\,18x^3 &+\,11x^2 &-\,3x \\
& &+\,3x^4 &+\,13x^3 &-\,18x^2 &+\,11x &-\,3
\end{array}$} \\
&= 3x^6 +16x^5 -2x^4 +6x^3 -10x^2 +8x -3
\end{align*}
\end{document}