多个矩阵方程,对齐

多个矩阵方程,对齐

我想在多行上写三个矩阵方程,因此我使用alignat

在此处输入图片描述

但是,每行矩阵的宽度并不相等。我该如何确保它们相等?我一直在研究,tabstackengine但它在里面效果不太好alignat。我想避免使用\phantom。有什么建议吗?

\documentclass[11pt,twoside,a4paper]{article}
\usepackage{amsmath}

\begin{alignat}{3}
& \begin{bmatrix} X \\ Y \\ Z \end{bmatrix} &&= \textbf{T}_3 (\phi) \begin{bmatrix} X \\ Y \\ Z \end{bmatrix} &&= \begin{bmatrix}
        \text{cos($\psi$)} & \text{sin($\psi$)} & 0\\
        \text{-sin($\psi$)} & \text{cos($\psi$)} & 0 \\
        0 & 0 & 1 \\
    \end{bmatrix}
    \begin{bmatrix}
        X \\
        Y \\
        Z \\
    \end{bmatrix} \\
& \begin{bmatrix} X' \\ Y' \\ Z' \end{bmatrix} &&= \textbf{T}_2 (\theta) \begin{bmatrix} X' \\ Y' \\ Z' \end{bmatrix} &&= \begin{bmatrix}
        \text{cos($\theta$)} & 0 & \text{-sin($\theta$)}\\
        0 & 1 & 0 \\
        \text{sin($\theta$)} & 0 & \text{cos($\theta$)} \\
    \end{bmatrix}
    \begin{bmatrix}
        X' \\
        Y' \\
        Z' \\
    \end{bmatrix} \\
& \begin{bmatrix} X'' \\ Y'' \\ Z'' \end{bmatrix} &&= \textbf{T}_1 (\psi) \begin{bmatrix} X'' \\ Y'' \\ Z'' \end{bmatrix} &&= \begin{bmatrix}
        1 & 0 & 0\\
        0 & \text{cos($\phi$)} & \text{sin($\phi$)} \\
        0 & \text{-sin($\phi$)} & \text{cos($\phi$)} \\
    \end{bmatrix}
    \begin{bmatrix}
        X'' \\
        Y'' \\
        Z'' \\
    \end{bmatrix}
\end{alignat}

答案1

这里,\eqstencil必须为您的方程式量身定制。

重新修改答案,使变换矩阵的总宽度均匀,列间宽度固定(使用 TABstacks),并增加垂直行间距。

\documentclass[11pt,twoside,a4paper]{article}
\usepackage{amsmath,tabstackengine}
\setstackEOL{ }
\setstackgap{L}{16pt}
\fixTABwidth{T}
\stackMath
\newsavebox\boxA
\newsavebox\boxB
\newsavebox\boxC
\newcommand\eqstencil[3]{%
  \savebox\boxA{$X''$}
  \savebox\boxB{$\textbf{T}_3 (\psi)$}
  \savebox\boxC{\setstackEOL{\cr}\csname xform3\endcsname{\psi}}
  \begin{bmatrix}\makebox[\wd\boxA]{\Centerstack{X#1 Y#1 Z#1}}\end{bmatrix} 
  = 
  \makebox[\wd\boxB][l]{$\textbf{T}_#2 (#3) $}
  \begin{bmatrix}\makebox[\wd\boxA]{%
    \Centerstack{X#1 Y#1 Z#1}}\end{bmatrix} 
  = 
  \begin{bmatrix}\makebox[\wd\boxC]{\setstackEOL{\cr}\csname xform#2\endcsname{#3}}\end{bmatrix}
  \begin{bmatrix}\makebox[\wd\boxA]{\Centerstack{X#1 Y#1 Z#1}}\end{bmatrix}}
\expandafter\def\csname xform1\endcsname#1{%
   \tabbedCenterstack{
     \cos(#1) & 0 & -\sin(#1) \cr
     0 & 1 & 0 \cr
     \sin(#1) & 0 & \cos(#1)
   }}
\expandafter\def\csname xform2\endcsname#1{%
   \tabbedCenterstack{
     \cos(#1) & 0 & -\sin(#1) \cr
     0 & 1 & 0 \cr
     \sin(#1) & 0 & \cos(#1)
   }}
\expandafter\def\csname xform3\endcsname#1{%
  \tabbedCenterstack{
    1 & 0 & 0 \cr
    0 & \cos(#1) & \sin(#1) \cr
    0 & -\sin(#1) & \cos(#1)
  }}
\begin{document}
\begin{alignat}{3}
& \eqstencil{}{3}{\psi}\\[5pt]
& \eqstencil{'}{2}{\theta} \\[5pt]
& \eqstencil{''}{1}{\phi}
\end{alignat}
\end{document}

在此处输入图片描述


修改答案以使矢量宽度相等

\documentclass[11pt,twoside,a4paper]{article}
\usepackage{amsmath,stackengine}
\setstackgap{L}{12pt}
\stackMath
\newsavebox\boxA
\newsavebox\boxB
\newsavebox\boxC
\newcommand\eqstencil[3]{%
  \savebox\boxA{$X''$}
  \savebox\boxB{$\textbf{T}_3 (\psi)$}
  \savebox\boxC{$\csname xform3\endcsname{\psi}$}
  \begin{bmatrix}\makebox[\wd\boxA]{\Centerstack{X#1 Y#1 Z#1}}\end{bmatrix} 
  = 
  \makebox[\wd\boxB][l]{$\textbf{T}_#2 (#3) $}
  \begin{bmatrix}\makebox[\wd\boxA]{\Centerstack{X#1 Y#1 Z#1}}\end{bmatrix} 
  = 
  \makebox[\wd\boxC]{$\csname xform#2\endcsname{#3}$}
  \begin{bmatrix}\makebox[\wd\boxA]{\Centerstack{X#1 Y#1 Z#1}}\end{bmatrix}}
\expandafter\def\csname xform1\endcsname#1{%
   \begin{bmatrix}
     \cos(#1) & 0 & -\sin(#1) \\
     0 & 1 & 0 \\
     \sin(#1) & 0 & \cos(#1) \\
   \end{bmatrix}}
\expandafter\def\csname xform2\endcsname#1{%
   \begin{bmatrix}
     \cos(#1) & 0 & -\sin(#1) \\
     0 & 1 & 0 \\
     \sin(#1) & 0 & \cos(#1) \\
   \end{bmatrix}}
\expandafter\def\csname xform3\endcsname#1{%
  \begin{bmatrix}
    1 & 0 & 0 \\
    0 & \cos(#1) & \sin(#1) \\
    0 & -\sin(#1) & \cos(#1) \\
  \end{bmatrix}}
\begin{document}
\begin{alignat}{3}
& \eqstencil{}{3}{\psi}\\
& \eqstencil{'}{2}{\theta} \\
& \eqstencil{''}{1}{\phi}
\end{alignat}
\end{document}

在此处输入图片描述


原始答案

\documentclass[11pt,twoside,a4paper]{article}
\usepackage{amsmath}
\newsavebox\boxA
\newsavebox\boxB
\newsavebox\boxC
\newcommand\eqstencil[3]{%
  \savebox\boxA{$\begin{bmatrix} X''\\Y''\\Z'' \end{bmatrix}$}
  \savebox\boxB{$\textbf{T}_3 (\psi)$}
  \savebox\boxC{$\csname xform3\endcsname{\psi}$}
  \makebox[\wd\boxA]{$\begin{bmatrix} X#1 \\ Y#1 \\ Z#1 \end{bmatrix}$} = 
  \makebox[\wd\boxB][l]{$\textbf{T}_#2 (#3) $}
  \makebox[\wd\boxA]{$\begin{bmatrix} X#1 \\ Y#1 \\ Z#1 \end{bmatrix}$} = 
  \makebox[\wd\boxC]{$\csname xform#2\endcsname{#3}$}
  \makebox[\wd\boxA]{$\begin{bmatrix} X#1 \\ Y#1 \\ Z#1 \end{bmatrix}$}}
\expandafter\def\csname xform1\endcsname#1{%
   \begin{bmatrix}
     \cos(#1) & 0 & -\sin(#1) \\
     0 & 1 & 0 \\
     \sin(#1) & 0 & \cos(#1) \\
   \end{bmatrix}}
\expandafter\def\csname xform2\endcsname#1{%
   \begin{bmatrix}
     \cos(#1) & 0 & -\sin(#1) \\
     0 & 1 & 0 \\
     \sin(#1) & 0 & \cos(#1) \\
   \end{bmatrix}}
\expandafter\def\csname xform3\endcsname#1{%
  \begin{bmatrix}
    1 & 0 & 0 \\
    0 & \cos(#1) & \sin(#1) \\
    0 & -\sin(#1) & \cos(#1) \\
  \end{bmatrix}}
\begin{document}
\begin{alignat}{3}
& \eqstencil{}{3}{\psi}\\
& \eqstencil{'}{2}{\theta} \\
& \eqstencil{''}{1}{\phi}
\end{alignat}
\end{document}

在此处输入图片描述

通过在 es 上设置对齐,可以获得不同的对齐\makebox。例如,重新定义

\newcommand\eqstencil[3]{%
  \savebox\boxA{$\begin{bmatrix} X''\\ Y''\\Z'' \end{bmatrix}$}
  \savebox\boxB{$\textbf{T}_3 (\psi)$}
  \savebox\boxC{$\csname xform3\endcsname{\psi}$}
  \makebox[\wd\boxA][r]{$\begin{bmatrix} X#1 \\ Y#1 \\ Z#1 \end{bmatrix}$} = 
  \makebox[\wd\boxB][l]{$\textbf{T}_#2 (#3) $}
  \makebox[\wd\boxA][r]{$\begin{bmatrix} X#1 \\ Y#1 \\ Z#1 \end{bmatrix}$} = 
  \makebox[\wd\boxC][r]{$\csname xform#2\endcsname{#3}$}
  \makebox[\wd\boxA][l]{$\begin{bmatrix} X#1 \\ Y#1 \\ Z#1 \end{bmatrix}$}}

给出

在此处输入图片描述

答案2

您可以根据方程式中最宽的元素来分隔每个矩阵中的每个条目。为此,该命令\spaceto{<source>}{<target>}使用和\ooalign创建一个“符号叠加” :\phantom{<source>}<target>

在此处输入图片描述

\documentclass{article}
\usepackage{amsmath}

\newcommand{\spaceto}[2]{{\ooalign{$\phantom{#1}$\cr\hidewidth$#2$\hidewidth}}}

\begin{document}

% Original layout
\begin{alignat}{3}
& \begin{bmatrix} X \\ Y \\ Z \end{bmatrix} &&= \textbf{T}_3 (\phi) \begin{bmatrix} X \\ Y \\ Z \end{bmatrix} &&= \begin{bmatrix}
        \text{cos($\psi$)} & \text{sin($\psi$)} & 0\\
        \text{-sin($\psi$)} & \text{cos($\psi$)} & 0 \\
        0 & 0 & 1 \\
    \end{bmatrix}
    \begin{bmatrix}
        X \\
        Y \\
        Z \\
    \end{bmatrix} \\
& \begin{bmatrix} X' \\ Y' \\ Z' \end{bmatrix} &&= \textbf{T}_2 (\theta) \begin{bmatrix} X' \\ Y' \\ Z' \end{bmatrix} &&= \begin{bmatrix}
        \text{cos($\theta$)} & 0 & \text{-sin($\theta$)}\\
        0 & 1 & 0 \\
        \text{sin($\theta$)} & 0 & \text{cos($\theta$)} \\
    \end{bmatrix}
    \begin{bmatrix}
        X' \\
        Y' \\
        Z' \\
    \end{bmatrix} \\
& \begin{bmatrix} X'' \\ Y'' \\ Z'' \end{bmatrix} &&= \textbf{T}_1 (\psi) \begin{bmatrix} X'' \\ Y'' \\ Z'' \end{bmatrix} &&= \begin{bmatrix}
        1 & 0 & 0\\
        0 & \text{cos($\phi$)} & \text{sin($\phi$)} \\
        0 & \text{-sin($\phi$)} & \text{cos($\phi$)} \\
    \end{bmatrix}
    \begin{bmatrix}
        X'' \\
        Y'' \\
        Z'' \\
    \end{bmatrix}
\end{alignat}

% Original layout
\begin{alignat}{3}
& \begin{bmatrix} \spaceto{X''}{X} \\ Y \\ Z \end{bmatrix} &&= \spaceto{\textbf{T}_1(\psi)}{\textbf{T}_3 (\phi)} \begin{bmatrix} \spaceto{X''}{X} \\ Y \\ Z \end{bmatrix} &&= \begin{bmatrix}
        \cos(\psi) & \sin(\psi) & \spaceto{-\sin(\theta)}{0} \\
        -\sin(\psi) & \cos(\psi) & 0 \\
        0 & \spaceto{-\sin(\phi)}{0} & 1 \\
    \end{bmatrix}
    \begin{bmatrix}
        \spaceto{X''}{X} \\
        Y \\
        Z \\
    \end{bmatrix} \\
& \begin{bmatrix} \spaceto{X''}{X'} \\ Y' \\ Z' \end{bmatrix} &&= \spaceto{\textbf{T}_1(\psi)}{\textbf{T}_2 (\theta)} \begin{bmatrix} \spaceto{X''}{X'} \\ Y' \\ Z' \end{bmatrix} &&= \begin{bmatrix}
        \cos(\theta) & \spaceto{-\sin(\phi)}{0} & -\sin(\theta) \\
        \spaceto{-\sin(\psi)}{0} & 1 & 0 \\
        \sin(\theta) & 0 & \cos(\theta) \\
    \end{bmatrix}
    \begin{bmatrix}
        \spaceto{X''}{X'} \\
        Y' \\
        Z' \\
    \end{bmatrix} \\
& \begin{bmatrix} X'' \\ Y'' \\ Z'' \end{bmatrix} &&= \textbf{T}_1 (\psi) \begin{bmatrix} X'' \\ Y'' \\ Z'' \end{bmatrix} &&= \begin{bmatrix}
        1 & 0 & \spaceto{-\sin(\theta)}{0}\\
        \spaceto{-\sin(\psi)}{0} & \cos(\phi) & \sin(\phi) \\
        0 & -\sin(\phi) & \cos(\phi) \\
    \end{bmatrix}
    \begin{bmatrix}
        X'' \\
        Y'' \\
        Z'' \\
    \end{bmatrix}
\end{alignat}

\end{document}

请注意,打印切线函数时无需使用\text。使用运算符\sin\cos

答案3

我对你的请求没有解决方案,但有另外两个建议。我不会扩大矩阵中的空白,但会尝试添加更多对齐以使其更整洁。第二种方法是简化整个过程并完全避免它。顺便问一句。你为什么不喜欢幻影?这将是这里的典型方式,并且在上述代码中只需要六次......

% arara: pdflatex

\documentclass[11pt,twoside,a4paper]{article}
\usepackage{mathtools}
\newcommand*{\whateveryoutrytosaywiththat}[1]{\mathbf{#1}} % use custom commands which explain your syntax and make it changeable afterwards.

\begin{document}
You could try
\begin{alignat}{3}
\begin{bmatrix} 
X \\ Y \\ Z 
\end{bmatrix} 
&= \whateveryoutrytosaywiththat{T}_3(\phi) 
&\begin{bmatrix} 
X \\ Y \\ Z 
\end{bmatrix}
&= \begin{bmatrix}
\cos(\psi) & \sin(\psi) & 0\\
-\sin(\psi) & \cos(\psi) & 0 \\
0 & 0 & 1 \\
\end{bmatrix}
&&\begin{bmatrix}
X \\
Y \\
Z \\
\end{bmatrix} \\
\begin{bmatrix} 
X' \\ Y' \\ Z' 
\end{bmatrix} 
&= \whateveryoutrytosaywiththat{T}_2(\theta) 
&\begin{bmatrix} X' \\ Y' \\ Z' 
\end{bmatrix} 
&= 
\begin{bmatrix}
\cos(\theta) & 0 & -\sin(\theta)\\
0 & 1 & 0 \\
\sin(\theta) & 0 & \cos(\theta) \\
\end{bmatrix}
&&\begin{bmatrix}
X' \\
Y' \\
Z' \\
\end{bmatrix} \\
\begin{bmatrix} 
X'' \\ Y'' \\ Z'' 
\end{bmatrix} 
&= \whateveryoutrytosaywiththat{T}_1(\psi) 
&\begin{bmatrix} X'' \\ Y'' \\ Z'' 
\end{bmatrix} 
&= 
\begin{bmatrix}
1 & 0 & 0\\
0 & \cos(\phi) & \sin(\phi) \\
0 & -\sin(\phi) & \cos(\phi) \\
\end{bmatrix}
&&\begin{bmatrix}
X'' \\
Y'' \\
Z'' \\
\end{bmatrix}
\end{alignat}
or you do
\begin{alignat}{3}
\vec{A} 
&= \whateveryoutrytosaywiththat{T}_3(\phi) 
\vec{A}
&&= \begin{bmatrix}
\cos(\psi) & \sin(\psi) & 0\\
-\sin(\psi) & \cos(\psi) & 0 \\
0 & 0 & 1 \\
\end{bmatrix}
&&\vec{A} \\
\vec{A'} 
&= \whateveryoutrytosaywiththat{T}_2(\theta) 
\vec{A'}
&&= 
\begin{bmatrix}
\cos(\theta) & 0 & -\sin(\theta)\\
0 & 1 & 0 \\
\sin(\theta) & 0 & \cos(\theta) \\
\end{bmatrix}
&&\vec{A'} \\
\vec{A''} 
&= \whateveryoutrytosaywiththat{T}_1(\psi) 
\vec{A''} 
&&= 
\begin{bmatrix}
1 & 0 & 0\\
0 & \cos(\phi) & \sin(\phi) \\
0 & -\sin(\phi) & \cos(\phi) \\
\end{bmatrix}
&&\vec{A''}
\end{alignat}
where
\[
\vec{A}=\begin{bmatrix} 
    X \\ Y \\ Z 
\end{bmatrix}\wedge
\vec{A'}=\begin{bmatrix} 
X' \\ Y' \\ Z' 
\end{bmatrix}\wedge
\vec{A''}=\begin{bmatrix} 
X'' \\ Y'' \\ Z'' 
\end{bmatrix}
\]
\end{document}

在此处输入图片描述

答案4

我刚开始使用 LaTeX 不久,这是我的第一个答案。无论如何,我会使用{easybmat}此处显示的包来做类似的事情。http://cs.brown.edu/about/system/managed/latex/doc/docbmat.pdf

        \documentclass[11pt,twoside,a4paper]{article}
        \usepackage{amsmath}
        \usepackage{easybmat}

        \begin{document}

        \begin{alignat}{4}
        &
        \left[
                \begin{BMAT}(,20pt, 15pt){c}{ccc}
                     X \\ 
                     Y \\ 
                     Z 
                 \end{BMAT} 
        \right]
                 &&= \textbf{T}_3 (\phi) 
        && \left[
                \begin{BMAT}(,20pt, 15pt){c}{ccc}
                     X \\
                     Y \\
                     Z 
                 \end{BMAT} 
        \right]
        &&= \left[
                \begin{BMAT}(,26pt, 15pt){ccc}{ccc}
                \text{cos($\psi$)} & \text{sin($\psi$)} & 0\\
                \text{-sin($\psi$)} & \text{cos($\psi$)} & 0 \\
                0 & 0 & 1 \\
                 \end{BMAT} 
            \right]
        \left[
                \begin{BMAT}(,20pt, 15pt){c}{ccc}
                     X \\ 
                     Y \\ 
                     Z 
                 \end{BMAT} 
                    \right] \\
        & \left[
                \begin{BMAT}(,20pt, 15pt){c}{ccc}
                     X' \\
                     Y' \\
                      Z' 
                 \end{BMAT} 
            \right]
             &&= \textbf{T}_2 (\theta)
        &&    \left[
                \begin{BMAT}(,19pt, 15pt){c}{ccc}
                 X' \\
                 Y' \\
                  Z' 
                 \end{BMAT} 
             \right]
        &&= \left[
                \begin{BMAT}(,30pt, 15pt){ccc}{ccc}
                \text{cos($\theta$)} & 0 & \text{-sin($\theta$)}\\
                0 & 1 & 0 \\
                \text{sin($\theta$)} & 0 & \text{cos($\theta$)} \\
                 \end{BMAT} 
                   \right]
        \left[
                \begin{BMAT}(,20pt, 15pt){c}{ccc}
                X' \\
                Y' \\
                Z' \\
                 \end{BMAT} 
                    \right] \\
        & \left[
                \begin{BMAT}(,20pt, 15pt){c}{ccc}
                 X'' \\
                 Y'' \\
                 Z'' 
                 \end{BMAT} 
                    \right]
             &&= \textbf{T}_1 (\psi)
        && \left[
            \begin{BMAT}(,19pt, 15pt){c}{ccc}
                X'' \\
               Y'' \\
               Z'' 
            \end{BMAT}
           \right]
        &&= \left[
            \begin{BMAT}(,28pt, 15pt){ccc}{ccc}
                1 & 0 & 0\\
                0 & \text{cos($\phi$)} & \text{sin($\phi$)} \\
                0 & \text{-sin($\phi$)} & \text{cos($\phi$)} \\
            \end{BMAT} 
                \right]     
              \left[
            \begin{BMAT}(,20pt, 15pt){c}{ccc}
                X'' \\
                Y'' \\
                Z'' \\
            \end{BMAT} 
                \right]     
        \end{alignat}

   \end{document}

在此处输入图片描述

相关内容