在矩阵中对齐负十进制数

在矩阵中对齐负十进制数

如何对齐表格中矩阵中的负十进制数,就像对齐siunitx表格中的数字一样(我使用的是类 elsarticle 选项:twocolumn)

    \documentclass[5p,twocolumn]{elsarticle}

    \usepackage{booktabs,tabularx}
    \usepackage{amsmath}

\begin{document}
    \begin{table}
    \caption{Algorithm 3 Illustrative calculation for Numerical Example 2}
        \label{tab:Example 2.2}
    %    \centering
    \footnotesize%scriptsize
    \setlength\tabcolsep{1pt}
    \setlength\arraycolsep{2pt}
    \begin{tabular}{ll}
        \toprule
    \normalfont Algorithm steps 
        & Numerical computation\\
        \midrule
    Input  &   Given\\
      & $ \mathbf{U}|_{\theta=0.5} = \begin{bmatrix} -1 & 1 & 0.2298 & 0.5000 & 0.7702 & 0.1250 \end{bmatrix}^T$\\
      & $\mathbf{U}'_{\theta}|_{\theta =0.5} = \begin{bmatrix} -2 & 2 & 0.8415 & 1 & -0.8415 & 0.7500  \end{bmatrix}^T$\\
      & $ \mathbf{v} = \begin{bmatrix} -2.7063 & 1.0000 & 0.2298 & 0.5000 & 0.7702 & 0.1250 \end{bmatrix}^T$\\
      & $ \mathbf{u} = \begin{bmatrix} -0.8905 & 0.3290 & 0.0756 & 0.1645 & 0.2534 & 0.0411 \end{bmatrix}^T$\\
        \midrule
    Step 1: & Compute $\|\mathbf{U}\|'_{\theta} = 2.4257$\\ 
    Step 3: & Compute $\mathbf{v}'_{\theta} =$ \\
       & $\begin {bmatrix} 
        -4.4257 & 2.0000 & 0.8415 & 1.0000 & -0.8415 & 0.7500 
         \end{bmatrix}^T$\\ 
    Step 7: & Compute $\|\mathbf{v}'_{\theta}\| = 4.6451$\\  
    Step 8: & Compute $\mathbf{u}'_{\theta} = $ \\
       & $\begin {bmatrix} 
        -0.0952 & 0.1552 & 0.1613 & 0.0776 & -0.6642 & 0.1839 
         \end{bmatrix}^T$\\
    Step 9: & Compute $ \mathbf{Q}'_{\theta} = $\\
       &   $\begin{bmatrix} 
        -0.3390 &  0.3390 &  0.3017 &  0.1695 & -1.1348 &  0.3354\\ 
         0.3390 &  0.2042 & -0.1296 & -0.1021 &  0.3585 & -0.1338\\ 
         0.3017 & -0.1296 & -0.0488 & -0.0648 &  0.0178 & -0.0411\\
         0.1695 & -0.1021 & -0.0648 & -0.0511 &  0.1792 & -0.0669\\ 
        -1.1348 &  0.3585 &  0.0187 &  0.1792 &  0.6733 & -0.0386\\ 
         0.3354 & -0.1338 & -0.0411 & -0.0669 & -0.0386 & -0.0303
            \end{bmatrix}$\\
    Step 10: & Extract $\mathbf{Q}'_{\theta} = \mathbf{Q}'_{\theta}(1,1:6)= $\\ 
      &$\begin{bmatrix} -0.3390 & 0.3390 & 0.3017 & 0.1695 & -1.1348 & 0.3354 \end{bmatrix}^T$\\
    Step 11: & $\mathbf{R}'_{\theta} = \begin{bmatrix} 2.4257 \end{bmatrix}$ \\
    \midrule
    Output & $\mathbf{R}'|_{\theta = 0.5} = \begin{bmatrix} 2.4257 \end{bmatrix}$\\
    \midrule
    Test & Accuracy of the computations:\\
    & $\|(\mathbf{U}^T\mathbf{U})'_{\theta}|_{\theta=0.5} - (\mathbf{R}^T\mathbf{R})'_{\theta}|_{\theta=0.5}\|=1.7764\cdot10^{-15}$\\
    \bottomrule
    \end{tabular}
    \end{table}
\end{document}

答案1

由于所有数字的位数完全相同,只是有无减号不同,因此最简单的方法是使用包bmatrix*中的环境右对齐矩阵的列mathtools。请参阅答案这个问题以了解更多对齐矩阵元素的方法。

\documentclass[5p,twocolumn]{elsarticle}

\usepackage{booktabs,tabularx}
\usepackage{amsmath}
\usepackage{mathtools}

\begin{document}

\footnotesize
\setlength\tabcolsep{1pt}
\setlength\arraycolsep{2pt}
\begin{tabular}{ll}
    Step 9: & Compute $ \mathbf{Q}'_{\theta} = $\\
    & $\begin{bmatrix*}[r] 
    -0.3390 &  0.3390 &  0.3017 &  0.1695 & -1.1348 &  0.3354\\ 
     0.3390 &  0.2042 & -0.1296 & -0.1021 &  0.3585 & -0.1338\\ 
     0.3017 & -0.1296 & -0.0488 & -0.0648 &  0.0178 & -0.0411\\
     0.1695 & -0.1021 & -0.0648 & -0.0511 &  0.1792 & -0.0669\\ 
    -1.1348 &  0.3585 &  0.0187 &  0.1792 &  0.6733 & -0.0386\\ 
     0.3354 & -0.1338 & -0.0411 & -0.0669 & -0.0386 & -0.0303
    \end{bmatrix*}$
\end{tabular}

\end{document}

在此处输入图片描述

答案2

对于负数的对齐,解决方案与bmatrix*from相同。此外,我建议定义一个新的浮点数 ( ),它有自己的计数器;此外,我还改进了多个下标的对齐,并定义了一个命令,带有星号版本,可自动根据其内容调整其大小。mathtoolsalgonorm

\documentclass[5p,twocolumn]{elsarticle}
\usepackage{booktabs,tabularx, float, caption}
\usepackage{mathtools}
    \DeclarePairedDelimiter{\abs}{\lvert}{\rvert}
    \DeclarePairedDelimiter{\norm}{\lVert}{\rVert}
\floatstyle{plaintop}
\newfloat{algo}{tbp}{loa}{}
\floatname{algo}{Algorithm}
\usepackage{lipsum}

\begin{document}

\lipsum[1]
\setcounter{algo}{2}
\begin{algo}
\captionsetup{font=footnotesize, labelfont=bf, singlelinecheck=off}
\caption{Illustrative calculation for Numerical Example 2}
    \label{alg:Example 2.2}
% \centering
\footnotesize%scriptsize
\setlength\tabcolsep{1pt}
\setlength\arraycolsep{2pt}
\delimitershortfall=-1sp
%\setlength{\extrarowheight}{3pt}
\begin{tabular}{p{15mm}l@{}}
    \toprule
\multicolumn{2}{l}{\normalfont Algorithm steps.\quad Numerical computation}\\
    \midrule
Input & Given\\
  & $ \mathbf{U}|_{\theta=0.5} = \begin{bmatrix} -1 & 1 & 0.2298 & 0.5000 & 0.7702 & 0.1250 \end{bmatrix}^T$\\
  & $\mathbf{U}'_{\theta\smash{\bigm|}\theta=0.5} = \begin{bmatrix} -2 & 2 & 0.8415 & 1 & -0.8415 & 0.7500 \end{bmatrix}^T$\\
  & $ \mathbf{v} = \begin{bmatrix} -2.7063 & 1.0000 & 0.2298 & 0.5000 & 0.7702 & 0.1250 \end{bmatrix}^T$\\
  & $ \mathbf{u} = \begin{bmatrix} -0.8905 & 0.3290 & 0.0756 & 0.1645 & 0.2534 & 0.0411 \end{bmatrix}^T$\\
    \midrule
Step 1: & Compute $\norm*{\mathbf{U}}'_{\theta} = 2.4257$\\
\addlinespace
Step 3: & Compute $\mathbf{v}'_{\theta} =$ \\
   & $\begin {bmatrix}
    -4.4257 & 2.0000 & 0.8415 & 1.0000 & -0.8415 & 0.7500
     \end{bmatrix}^T$\\
\addlinespace
Step 7: & Compute $\norm{\mathbf{v}'_{\theta}}= 4.6451$\\
\addlinespace
Step 8: & Compute $\mathbf{u}'_{\theta} = $ \\
   & $\begin {bmatrix}
    -0.0952 & 0.1552 & 0.1613 & 0.0776 & -0.6642 & 0.1839
     \end{bmatrix}^T$\\
\addlinespace
Step 9: & Compute $ \mathbf{Q}'_{\theta} = $\\
\multicolumn{2}{r}{$\begin{bmatrix*}[r]
    -0.3390 & 0.3390 & 0.3017 & 0.1695 & -1.1348 & 0.3354\\
     0.3390 & 0.2042 & -0.1296 & -0.1021 & 0.3585 & -0.1338\\
     0.3017 & -0.1296 & -0.0488 & -0.0648 & 0.0178 & -0.0411\\
     0.1695 & -0.1021 & -0.0648 & -0.0511 & 0.1792 & -0.0669\\
    -1.1348 & 0.3585 & 0.0187 & 0.1792 & 0.6733 & -0.0386\\
     0.3354 & -0.1338 & -0.0411 & -0.0669 & -0.0386 & -0.0303
        \end{bmatrix*}$}\\
\addlinespace
Step 10: & Extract $\mathbf{Q}'_{\theta} = \mathbf{Q}'_{\theta}(1,1:6)= $\\
  &$\begin{bmatrix} -0.3390 & 0.3390 & 0.3017 & 0.1695 & -1.1348 & 0.3354 \end{bmatrix}^T$\\
\addlinespace
Step 11: & $\mathbf{R}'_{\theta} = \begin{bmatrix} 2.4257 \end{bmatrix}$ \\
\midrule
\addlinespace
Output & $\mathbf{R}'|_{\theta = 0.5} = \begin{bmatrix} 2.4257 \end{bmatrix}$\\
\midrule
\addlinespace
Test & Accuracy of the computations:\\
& $\norm*{(\mathbf{U}^T\mathbf{U})'_{\theta\smash{\bigm|}\theta=0.5} - (\mathbf{R}^T\mathbf{R})'_{\theta\smash{\bigm|}\theta=0.5}}=1.7764\cdot10^{-15}$\\
\bottomrule
\end{tabular}
\end{algo}

\end{document}

在此处输入图片描述

相关内容