[Tex/LaTex] How to align integers on the right, but still center them

horizontal alignmenttables

Suppose we have a table like this:

\begin{tabular}{c}
Heading \\
1 \\
10 \\
100 \\
\end{tabular}

This will center all the numbers. If I want to align them to the right, I could change the column definition to r, but that would but the numbers on the right end of the table. What I would like is for the widest number (in this case 100) to be centered with respect to the column, and the others to be right-aligned to that number. There seem to be a bajillion packages out there that deal in one way or another with aligning numbers by their decimal points, but none seem to offer a simple way to pad numbers to a fixed width. Does anyone have a suggestion?

Best Answer

Using siunitx you'd do

\documentclass{article}
\usepackage{booktabs,siunitx}
\begin{document}
\begin{tabular}{S[table-format=3.0]}
\toprule
{Heading} \\
\midrule
1 \\
10 \\
100 \\
\bottomrule
\end{tabular}
\end{document}