I have a set of multiple equations with matrices and I would like that both the brackets and the elements are aligned together.
To do so, I followed the accepted answer given in this thread: Multiple matrix equations, alignment
However, with that solution I was able to align only the brackets and not the elements:
Is there a way to center-align also the different columns of the matrices and the first letter on the leftside of the equations?
Here the current code:
\documentclass[11pt,twoside,a4paper]{article}
\usepackage{amsmath}
\usepackage{tabstackengine}
\setstackEOL{ }
\setstackgap{L}{16pt}
\fixTABwidth{T}
\stackMath
\newsavebox\boxA
\newsavebox\boxB
\newcommand\eqstencil[3]{%
\savebox\boxA{$R_x\left(\theta _{y}\right)$}
\savebox\boxB{\setstackEOL{\cr}\csname xform2\endcsname{y}}
\makebox[\wd\boxA][l]{$#1$}
=
\begin{bmatrix}\makebox[\wd\boxB]{\setstackEOL{\cr}\csname xform#3\endcsname{#2}}\end{bmatrix}}
\expandafter\def\csname xform1\endcsname#1{%
\tabbedCenterstack{
1 & 0 & 0 & 0\cr
0 & \cos\left(\theta _{#1}\right) & -\sin\left(\theta _{#1}\right) & 0\cr
0 & \sin\left(\theta _{#1}\right) & \cos\left(\theta _{#1}\right) & 0\cr
0 & 0 & 0 & 1
}}
\expandafter\def\csname xform2\endcsname#1{%
\tabbedCenterstack{
\cos\left(\theta _{#1}\right) & 0 & \sin\left(\theta _{#1}\right) & 0\cr 0 & 1 & 0 & 0\cr -\sin\left(\theta _{#1}\right) & 0 & \cos\left(\theta _{#1}\right) & 0\cr 0 & 0 & 0 & 1
}}
\expandafter\def\csname xform3\endcsname#1{%
\tabbedCenterstack{
\cos\left(\theta _{#1}\right) & -\sin\left(\theta _{#1}\right) & 0 & 0\cr \sin\left(\theta _{#1}\right) & \cos\left(\theta _{#1}\right) & 0 & 0\cr 0 & 0 & 1 & 0\cr 0 & 0 & 0 & 1
}}
\expandafter\def\csname xform4\endcsname#1{%
\tabbedCenterstack{
1 & 0 & 0 & \Delta _{x}\cr 0 & 1 & 0 & \Delta _{y}\cr\ 0 & 0 & 1 & \Delta _{z}\cr 0 & 0 & 0 & 1
}}
\begin{document}
\begin{alignat}{4}
& \eqstencil{R_x\left(\theta _{x}\right)}{x}{1}\\[5pt]
& \eqstencil{R_y\left(\theta _{y}\right)}{y}{2}\\[5pt]
& \eqstencil{R_z\left(\theta _{z}\right)}{z}{3}\\[5pt]
& \eqstencil{T}{}{4}
\end{alignat}
\end{document}