# array/matrix specify default alignment

normally you write a matrix something like this

\begin{align*}
\begin{pmatrix}
ele1 & ele2 & ele3 \\
longEle1 & longEle2 & longEle3
\end{pmatrix}
\end{align*}

the elements inside the matrix now will be centred to each other. With this little patch

\makeatletter
\renewcommand*\env@matrix[1][*\c@MaxMatrixCols c]{
\hskip -\arraycolsep
\let\@ifnextchar\new@ifnextchar
\array{#1}
}
\makeatother

one is able to write matrices like this:

\begin{align*}
\begin{pmatrix}[rrr]
ele1 & ele2 & ele3 \\
longEle1 & longEle2 & longEle3
\end{pmatrix}
\end{align*}

and specify the alignment of the elements this way.

Now I'm searching for a way to redefine the default alignment in the array env (and therefore for matrices too) somehow.

From what I found out, it should be somewhere in the declaration of the array.sty, but up to now, I didn't found it.

I found only this paragraph in the array doc (see https://www.ctan.org/pkg/array, page 31):

@tabarray

This macro tests for an optional bracket and then calls up \@@array or \@@array[c] (as default).

343 〈*package〉344\def\@tabarray{\@ifnextchar[{\@@array}{\@@array[c]}}

But changing this line in the /usr/share/texmf-dist/tex/latex/tools/array.sty (in my version this was in line 324) didn't help.

Does someone know how to do this?

This way:

\makeatletter
\renewcommand*\env@matrix[1][*\c@MaxMatrixCols r]{%
\hskip -\arraycolsep
\let\@ifnextchar\new@ifnextchar
\array{#1}
}
\makeatother

All the columns will be of type r by default but we can still specify the preamble (eg. ccc).

• Could you expand this, so that if necessary you can still specify the formatting? – atticus May 16 at 15:27
• I have changed my post. – F. Pantigny May 16 at 15:33
• Oh sorry that was stupid, didn't saw this little c in my own code, which I'd have to change. Thought this would be something that had to be set for the whole array environment. Thanks a lot. – atticus May 16 at 15:35