Aligning numbers by decimal points in table columns
The newest option is using the S
column type of the siunitx
package.
\documentclass{article}
\usepackage{siunitx}
\begin{document}
\begin{tabular}{S[table-format=3.2]}% syntax for siunitx v2; for v1 use "tabformat"
555 \\
7.77 \\
99.9
\end{tabular}
\end{document}
Even though it's already been mentioned in the posting, it's worth discussing the dcolumn package in more detail. The package provides a column type called D
that performs alignment on the decimal marker. The D
column type takes three inputs: the input decimal marker (usually .
or ,
), the output decimal marker (again, usually .
or ,
), and the number of digits before and after the decimal marker. If the input and output decimal markers are always the same -- e.g., always .
-- it's useful to set up a short-hand as follows:
\newcolumntype{d}[1]{D{.}{.}{#1}}
Here's a full MWE that's based on @lockstep's code -- indeed, with this simple example the outputs of S[table-format=3.2]
and D{.}{.}{3.2}
are identical :
\documentclass{article}
\usepackage{dcolumn}
\newcolumntype{d}[1]{D{.}{.}{#1}}
\begin{document}
\begin{tabular}{d{3.2}}
555 \\
7.77 \\
99.9
\end{tabular}
\end{document}