# How to center values of an r@{}l column? (r@{}l aligns all column numbers along their decimal points)

Writing

\documentclass{article}
\begin{document}
\begin{table}
\begin{tabular}{lr@{}lr@{}l}
\hline
& \multicolumn{2}{c}{First column} & \multicolumn{2}{c}{Second column}  \\
\hline
Variable Name & 98 & .1234567 & 1234 & .56  \\
& (0 & .6789)   &  (54 & .3)  \\
\hline
\end{tabular}
\end{table}
\end{document}


results in

This is a variant of the code from this answer.

The column captions “First column” and “Second column” are perfectly centred due to \multicolumn{2}{c}{First column} and \multicolumn{2}{c}{Second column}. The numbers, however, are left-justified because of r@{}l but I would like to centre them below the column captions. I tried editing r@{}l but this did not help because it is required to stay this way in order to align all numbers along their decimal points.

I chose this solution because it does not need any packages and the siunitx package does not work on my computer (I don’t know why that is).

So, is there a way to solve this problem without packages (or at least without siunitx)?

• It would be simpler to do with siunitx, and the S column type. – Bernard Jul 7 '19 at 13:36
• I'd investigate why siunitx doesn't work. Did you do a thorough update to your TeX distribution? What is it? – egreg Jul 7 '19 at 13:42
• The dcolumn package might be an alternative. – leandriis Jul 7 '19 at 14:02
• @Incognito .. You already have 3 questions with no one of them having an accepted from you question (possibly neither upvoted) ... This is possible to make (at least some) users to avoid answering to your next questions, not because they will not get points but because these answers/questions will be possibly useless to future users since they won't really know if the answers there solves the initial problem and they could "google" again for a better luck on their problem – koleygr Jul 8 '19 at 9:42

I'd investigate why siunitx doesn't work.

Anyway, you can use dcolumn.

\documentclass{article}
\usepackage{dcolumn,booktabs}

\begin{document}

\begin{table}
\centering

\begin{tabular}{l D{.}{.}{2.7} D{.}{.}{4.2} }
\toprule
& \multicolumn{1}{c}{First column} & \multicolumn{1}{c}{Second column}  \\
\midrule
Variable Name & 98.1234567 & 1234.56  \\
& (0.6789)   &  (54.3)  \\
\bottomrule
\end{tabular}

\end{table}

\end{document}


Take a look at siunitxpackage but this could be out of topic... So, a manual fix could be to ad an \hspace{} command with a distance selected after tests to every element of the first raw you wish to center:

\documentclass{article}
\begin{document}
\begin{table}
\begin{tabular}{lr@{}lr@{}l}
\hline
& \multicolumn{2}{c}{First column} & \multicolumn{2}{c}{Second column}  \\
\hline
Variable Name & \hspace{0.05cm} 98 & .1234567 & \hspace{0.6cm}1234 & .56  \\
& (0 & .6789)   &  (54 & .3)  \\
\hline
\end{tabular}
\end{table}
\end{document}


With siunitx (it works for me) and makecell:

\documentclass{article}
\usepackage{booktabs,
makecell}
\usepackage{siunitx}

\begin{document}
\begin{table}
\sisetup{input-symbols = ()}
\centering
\begin{tabular}{l S[table-format=2.7]
S[table-format=4.2]}
\toprule
& {\makecell{First column}} & {\makecell{Second column}}  \\
\midrule
Variable Name   & 98.123 456 7                & 1234.56  \\
& (0.6789)                  &  (54.3)  \\
\bottomrule
\end{tabular}
\end{table}
\end{document}