TeX - LaTeX Asked on December 1, 2020
Here is a matrix:
documentclass{article}
usepackage{amsmath}
begin{document}
begin{equation*}
begin{pmatrix}
1.41 & -1.73
2.718 & 3.14
end{pmatrix}
end{equation*}
end{document}
As you can see, the number of decimal points may be different, and some numbers are negative. I’d like to have the columns aligned on the decimal points.
Normally, I’d use a half-em space for "missing" digits and a hphantom-
– but I use a font where the digits are not the same width, so that is ruled out.
I skimmed through TeX.SE, but only found answers for tables, not matrices. I have also looked in the docs of amsmath
and mathtools
, to no avail.
I suspect I could use TikZ matrices for that, but I’d prefer to stay simple if possible.
Any suggestions?
With matrix
is not possible (at least easy), try with array with S
columns, which are defined in the siunitx
package.
documentclass{article}
usepackage{siunitx}
begin{document}
[
left(begin{array}{@{} S[table-format=1.3]S[table-format=-1.2] @{}}
1.41 & -1.73
2.718 & 3.14
end{array}right)
]
end{document}
Answered by Zarko on December 1, 2020
The phantom
can be used:
def {phantom{0}} def+{phantom{+}}
$$
pmatrix{ 1.41 & -1.73 cr
2.718 & +3.14 }
$$
Answered by wipet on December 1, 2020
With nicematrix
and siunitx
:
documentclass{article}
usepackage{nicematrix}
usepackage{siunitx}
begin{document}
[
begin{pNiceArray}{S[table-format=1.3]S[table-format=-1.2]}
1.41 & -1.73
2.718 & 3.14
end{pNiceArray}
]
end{document}
Answered by F. Pantigny on December 1, 2020
The only modification needed to the original post is the use of the S
columntype.
documentclass{article}
usepackage{mathtools}
usepackage{siunitx}
begin{document}
begin{equation}
label{eq:1}
begin{pmatrix*}[S]
1.41 & -1.73
2.718 & 3.14
end{pmatrix*}
end{equation}
end{document}
Answered by Máté Wierdl on December 1, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP