I'm working on creating a specific two-column table in \LaTeX. The second column, $f(n)$, contains expressions that are linear combinations of $\alpha$, $\beta$, and $\gamma$, but not all terms are present in every row.
My goal is to achieve a consistent column alignment for the coefficients of $\alpha$, $\beta$, and $\gamma$ across all rows, with consistent spacing around the $+$ signs. The terms $\alpha$, $\beta$, $\gamma$ themselves should also align.
To achieve this alignment, I currently rely heavily on \phantom{} and empty {} groups, which feels overly complicated. I suspect there is a much cleaner, more idiomatic approach that I am missing.
Since I'm not very proficient, could you please critique my current approach and suggest a more robust method to achieve this specific alignment?
Here is my current code snippet:
\documentclass{article}
\begin{document}
\[
\begin{array}{@{}c|c@{}}
n & f(n) \\
\hline
1 & \phantom{0}\alpha\phantom{{}+0\beta+0\gamma} \\
\hline
2 & 2\alpha+\phantom{0}\beta\phantom{{}+0\gamma} \\
3 & 2\alpha\phantom{{}+0\beta}+\phantom{0}\gamma \\
\hline
4 & 4\alpha+3\beta\phantom{{}+0\gamma} \\
5 & 4\alpha+2\beta+\phantom{0}\gamma \\
6 & 4\alpha+\phantom{0}\beta+2\gamma \\
7 & 4\alpha\phantom{{}+0\beta}+3\gamma \\
\hline
8 & 8\alpha+7\beta\phantom{{}+0\gamma} \\
9 & 8\alpha+6\beta+\phantom{0}\gamma
\end{array}
\]
\end{document}


