数字矩阵元素在小数点处垂直对齐

数字矩阵元素在小数点处垂直对齐

我有一个矩阵,其中的方程式包含数值项,如下所示

这个

我想将条目按小数点对齐,就像表格中那样。

这能做到吗?

编辑:

Matrix 代码是(来自 .lyx 文件)

\begin_inset Formula 
\[
M=\left(\begin{array}{cc}
1.2 & 34.5\\
-67.8 & 9.012
\end{array}\right)
\]
\end_inset

由于框架的原因,该Table的相关代码比较复杂:

\begin_inset Tabular
<lyxtabular version="3" rows="2" columns="2">
<features tabularvalignment="middle">
<column alignment="decimal" decimal_point="." valignment="top">
<column alignment="decimal" decimal_point="."   valignment="top">
<row>
<cell alignment="decimal" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
1.2
\end_layout

\end_inset
</cell>
<cell alignment="decimal" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
34.5
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="decimal" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
-67.8
\end_layout

\end_inset
</cell>
<cell alignment="decimal" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
9.012
\end_layout

\end_inset

答案1

您可以通过将每列拆分成两列并用句点分隔来实现预期结果:

\documentclass{article}

\begin{document}
    Matrix
    \begin{equation}
        M = \left(
        \begin{array}{r@{.}lr@{.}l}
            1&2     &   34&5    \\
            -67&8   &   9&012   \\
        \end{array}
        \right)
    \end{equation}
\end{document}

得出的结果为:

生产输出

答案2

带有库amsmath和包siunitxtabularray

\documentclass[border=3.141592, preview]{standalone}
\usepackage{tabularray}
\UseTblrLibrary{amsmath, siunitx}

\begin{document}
\[
M = \begin{+pmatrix}[colspec={S[table-format=-2.1]@{}S[table-format=-2.3]}]
1.2   & 34,5    \\
-67.8 & 9.012   \\
    \end{+pmatrix}
\]
\end{document}

在此处输入图片描述

答案3

{pNiceArray}和的nicematrix列。Ssiunitx

\documentclass{article}
\usepackage{nicematrix}
\usepackage{siunitx}

\begin{document}

\[
M = \begin{pNiceArray}{S[table-format=-2.1]@{}S[table-format=-2.3]}
1.2   & 34,5    \\
-67.8 & 9.012   \\
    \end{pNiceArray}
\]

\end{document}

上述代码的输出

答案4

这是一个采用基本array环境的解决方案。

在此处输入图片描述

\documentclass{article}
\usepackage{siunitx} % for 'S' column type

\begin{document}
\[
M=\left(
\begin{array}{@{} S[table-format=-2.1] S[table-format=2.3] @{}}
   1.2 & 34.5   \\
 -67.8 &  9.012
\end{array}
\right)
\]
\end{document}

相关内容