我有一个矩阵,其中的方程式包含数值项,如下所示
我想将条目按小数点对齐,就像表格中那样。
这能做到吗?
编辑:
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
答案2
带有库amsmath
和包siunitx
的tabularray
:
\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}