[Tex/LaTex] Equal spacing in matrix

matrices

I'm trying to create a matrix that has equal spacing between each of the columns, but so far I have not been very succesful. The code I'm using right now is

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\begin{align}
U &= \begin{pmatrix}
    e^{\frac{i}{\hbar}|A|t} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
    0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
    0 & 0 & e^{-\frac{i}{\hbar}|A|t} & 0 & 0 & 0 & 0 & 0 & 0\\
    0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0\\
    0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0\\
    0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0\\
    0 & 0 & 0 & 0 & 0 & 0 & e^{-\frac{i}{\hbar}|A|t} & 0 & 0\\
    0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0\\
    0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & e^{\frac{i}{\hbar}|A|t}
\end{pmatrix}
\end{align}

\end{document}

This generates rather ugly output, with the columns containing the exponentials much wider than the others:

enter image description here

I suppose this is a very stupid and elementary question, but a quick search didn't get me anywhere sadly.

Best Answer

Done as a TABstack. The package has a \fixTABwidth{T} option. I've also increased the vertical spacing between lines slightly, to give a more balanced look.

\documentclass{article}

\usepackage{tabstackengine}
\stackMath

\begin{document}

\begin{equation}
\setstackgap{L}{1.1\baselineskip}
\fixTABwidth{T}
U = \parenMatrixstack{
    e^{\frac{i}{\hbar}|A|t} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
    0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
    0 & 0 & e^{-\frac{i}{\hbar}|A|t} & 0 & 0 & 0 & 0 & 0 & 0\\
    0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0\\
    0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0\\
    0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0\\
    0 & 0 & 0 & 0 & 0 & 0 & e^{-\frac{i}{\hbar}|A|t} & 0 & 0\\
    0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0\\
    0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & e^{\frac{i}{\hbar}|A|t}
}
\end{equation}

\end{document}

enter image description here

It is actually not a "very stupid and elementary question", as given by the many upvotes at this question: Writing a table with equally spaced columns, based on the widest column

Related Question