我有一组带有矩阵的多重方程,我希望括号和元素都对齐在一起。
为此,我遵循了此主题中给出的可接受答案:多个矩阵方程,对齐
有没有办法使矩阵的不同列和方程式左侧的首字母也居中对齐?
当前代码如下:
\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}
答案1
可以\mathmakebox
在一行中使用来建立标准单元格宽度。它不有为第一行。
\documentclass[11pt,twoside,a4paper]{article}
\usepackage{mathtools}
\newlength{\cellwidth}
\settowidth{\cellwidth}{$\displaystyle -\sin\left(\theta _x\right)$}
\begin{document}
\begin{align}
R_x\left(\theta _{x}\right) &= \begin{bmatrix}
\mathmakebox[\cellwidth]{1} & \mathmakebox[\cellwidth]{0} & \mathmakebox[\cellwidth]{0} & \mathmakebox[\cellwidth]{0} \\
0 & \cos\left(\theta _{x}\right) & -\sin\left(\theta _{x}\right) & 0 \\
0 & \sin\left(\theta _{x}\right) & \cos\left(\theta _{x}\right) & 0 \\
0 & 0 & 0 & 1
\end{bmatrix} \\
R_y\left(\theta _{y}\right) &= \begin{bmatrix}
\mathmakebox[\cellwidth]{\cos\left(\theta _{y}\right)} & \mathmakebox[\cellwidth]{0}
& \mathmakebox[\cellwidth]{\sin\left(\theta _{y}\right)} & \mathmakebox[\cellwidth]{0} \\
0 & 1 & 0 & 0 \\
-\sin\left(\theta _{y}\right) & 0 & \cos\left(\theta _{y}\right) & 0 \\
0 & 0 & 0 & 1
\end{bmatrix} \\
R_z\left(\theta _{z}\right) &= \begin{bmatrix}
\mathmakebox[\cellwidth]{\cos\left(\theta _{z}\right)} & \mathmakebox[\cellwidth]{-\sin\left(\theta _{z}\right)}
& \mathmakebox[\cellwidth]{0} & \mathmakebox[\cellwidth]{0} \\
\sin\left(\theta _{z}\right) & \cos\left(\theta _{z}\right) & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1
\end{bmatrix} \\
T &= \begin{bmatrix}
\mathmakebox[\cellwidth]{1} & \mathmakebox[\cellwidth]{0} & \mathmakebox[\cellwidth]{0} & \mathmakebox[\cellwidth]{\Delta _{x}}\\
0 & 1 & 0 & \Delta _{y}\\
0 & 0 & 1 & \Delta _{z}\\
0 & 0 & 0 & 1
\end{bmatrix}
\end{align}
\end{document}
答案2
粗略地讲,这只是你的\savebox
“\makebox
技巧”的另一次迭代。
\documentclass[11pt,twoside,a4paper]{article}
\usepackage{amsmath}
\usepackage{tabstackengine}
\setstackEOL{ }
\setstackgap{L}{16pt}
\fixTABwidth{T}
\stackMath
\newsavebox\boxA
\newsavebox\boxB
\newsavebox\boxC
\newcommand\eqstencil[3]{%
\savebox\boxA{$R_x\left(\theta _{y}\right)$}
\savebox\boxB{\setstackEOL{\cr}\csname xform2\endcsname{y}}
\savebox\boxC{$-\cos\left(\theta _{#1}\right)$}
\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{
\makebox[\wd\boxC][c]{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}