I have an array
in which one of the columns is a polynomial, and I would like to align the terms of the polynomial for each row of the array.
My hack is to use \phantom
s all over the place, but is there a way to do this automatically? For instance, if I could make this part of the array act like some sort of align
environment?
Here is a MWE:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
What I have:
\[ \begin{array}{|r|c|}
\hline
S & P(x) \\
\hline
9 & x + x^2 + x^3 \\
10 & 3x + x^2 + x^3 \\
11 & x + 10x^3\\
\hline
\end{array} \]
What I want:
\[ \begin{array}{|r|c|}
\hline
S & P(x) \\
\hline
9 & \phantom{3}x + x^2 + \phantom{10}x^3 \\
10 & 3x + x^2 + \phantom{10}x^3 \\
11 & \phantom{3}x \phantom{{} + x^2 } + 10x^3\\
\hline
\end{array} \]
\end{document}