How to horizontally align headers and decimal centered cells
This is a job for siunitx
. This package makes available S
columns with many more features than those provided by dcolumn
. For instance, your case can be treated with
S[table-format=1.3]
where 1.3
specifies one digit for the integral part and three for the decimal part. You can use exponential (also known as scientific) notation with proper alignment and change easily many aspects of data typesetting.
\documentclass{article}
\usepackage{siunitx,booktabs}
\begin{document}
\begin{tabular}{l *{2}{S[table-format=1.3]} }
\toprule
& {Header 1} & {Header 2} \\
\midrule
Length & 1.489 & 2.569 \\
Width & 5 & 2.4\\
\bottomrule
\end{tabular}
\end{document}
I've added also the rules as drawn by booktabs
One place before the decimal separator, three after it, so use D{1.3}
\documentclass{article}
\usepackage{dcolumn}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{l D{.}{.}{1.3} D{.}{.}{1.3}}
\toprule
& \multicolumn{1}{c}{Header 1} & \multicolumn{1}{c}{Header 2} \\
\midrule
Length & 1.489 & 2.569 \\
Width & 5 & 2.4\\
\bottomrule
\end{tabular}
\end{document}