# How to align integers on the right, but still center them

Suppose we have a table like this:

\begin{tabular}{c}
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?

-

Using siunitx you'd do

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

-
I get the error table-format undefined in families key. – Björn Pollex Jan 18 '11 at 11:26
maybe you need to update your system to get the newest siunitx? – Juan A. Navarro Jan 18 '11 at 11:41
@Space: It works correctly for me. Maybe you have an old version of siunitx. – TH. Jan 18 '11 at 11:42
@Space_C0wb0y. I've used the settings appropriate for v2 of siunitx. If you have version 1 (which sounds likely) replace table-format by tabformat and use \multicolumn for the heading. – Joseph Wright Jan 18 '11 at 12:48
@Juan: You were right, I was still running Tex Live 2009. After updating, it works like a charm. – Björn Pollex Jan 18 '11 at 13:18

If you want it less complicated then use the \makebox directly for the numbers and \multicolumn for the header.

\documentclass[a5paper]{article}
\usepackage{array,calc}

\newcolumntype{C}{>{\FormatNo} c }
\def\FormatNo\ignorespaces#1\\{%
\ignorespaces\makebox[\widthof{000}][r]{#1}\tabularnewline}
\begin{document}

\begin{tabular}{C}

Just to be picky: \ignorespaces in the replacement text of the \FormatNo macro does nothing (apart expanding \makebox; its place should be before #1. – egreg Apr 18 '13 at 11:48