How to Insert Tables Aligned by Decimal Points in LaTeX
Code
To sort numbers by their decimal point in the table of $\TeX$, use the siunitx package.
S[table-format=x.y]
You can place the table contents inside the opening and closing of {tabular}, and an option like table-format=x.y specifies a maximum of x digits before the decimal point and a maximum of y digits after the decimal point.
- For example,
S[table-format=4.10]is used when aligning numbers with at most 4 digits before the decimal point and at most 10 digits after it.
\documentclass{article}
\usepackage{array, siunitx}
\begin{document}
\begin{table}[h]
\centering
\begin{tabular}{S[table-format=4.10]}
\hline
\text{value} \\
\hline
3.1415926535 \\
2.71828182 \\
123.4 \\
78.91 \\
\hline
\end{tabular}
\end{table}
\end{document}
The rendered result is aligned on the decimal point as follows.

