# Aligning Decimal Points in Table

I want to align two numbers in two different rows the decimal point.

I do see a link for that here: Aligning numbers by decimal points in table columns

However, I don't understand how to incorporate that into my code. What follows is a reduced version of my code.

\documentclass[12pt,english]{article}
\usepackage{longtable}
\usepackage{fullpage}
\usepackage{times}
\usepackage[flushleft]{threeparttable}
\usepackage[font=large,labelfont=bf,tableposition=top,textfont=bf]{caption}
\usepackage{tabularx}
\usepackage{booktabs}
\newcolumntype{C}{>{\centering\arraybackslash}X}

\begin{document}

\clearpage \newpage
\begin{table}[!ht]
\caption{Table Title}
\def\arraystretch{1.05}
\vspace{-0.2cm}
\begin{threeparttable}
\small
\begin{tabularx}{\textwidth}{l*{10}{C}}
& (1)  \\
Variable Name & 0.1234566  \\
& (0.1234566) \\
\end{tabularx}
\begin{tablenotes}
\vspace{0.1cm}
\footnotesize{

\item \noindent \hspace{-1.8mm} Notes:

\noindent Sources:
}
\end{tablenotes}
\end{threeparttable}
\end{table}

\end{document}

-

In addition to trying out the dcolumn package mentioned by @DavidCarlisle, you may also want to check out some of the capabilities of the siunitx package, specifically, its S column type. I've simplified your (not exactly minimal) working example to the example code below, in order to focus on the operation of this column type:

\documentclass[12pt]{article}
\usepackage{booktabs,mathptmx,siunitx}
\sisetup{input-symbols = {()},  % do not treat "(" and ")" in any special way
group-digits  = false} % no grouping of digits
\begin{document}
\begin{table}
\begin{tabular}{@{}l S[table-format=2.7] S[table-format=4.2] @{}}
\toprule
& \multicolumn{1}{c}{(1)} & \multicolumn{1}{c@{}}{(2)}  \\
\midrule
Variable Name & 98.1234567 & 1234.56  \\
& (0.6789) & (54.3)\\
\bottomrule
\end{tabular}
\end{table}
\end{document}


-
It may be worth nothing that dcolumn is included in the memoir package. –  Brian M. Hunt Mar 6 '12 at 15:13

It looks like you don't want tabularx at all, just use a normal tabular with a D column for your numeric columns, perhaps defined by

\newcolumntype{.}{D{.}{.}{-1}}


using the dcolumn package.

for completeness, complete example:

\documentclass[12pt]{article}
\usepackage{booktabs,dcolumn}

\begin{document}
\begin{table}
\begin{tabular}{@{}l*{2}{D{.}{.}{7}}@{}}
\toprule
& (1) & (2)  \\
\midrule
Variable Name & 98.1234567 & 1234.56  \\
& (0.6789) & (54.3)\\
\bottomrule
\end{tabular}
\end{table}
\end{document}


-
Thank you very much for getting back to me. Why don't I want tabularx? The rest of my table is designed using that, I think. I may be wrong. I tried changing the syntax from tabularx to tabular and it did not work. –  J G Feb 15 '12 at 23:50
saying "did not work" isn't very descriptive, Obviously if you switch to tabular (and it looks as if you should) you have to not use tabularx syntax, specifically the {\textwidth} argument and X columns. –  David Carlisle Feb 16 '12 at 0:30
@DavidCarisle. I don't understand what you are saying. Could you please take my code, and modify it to show what I should insert and where? I wouldn't normally ask for this, but I do not understand a lick of what you are saying. I am very grateful. This might help other people coming to this thread in the future. –  J G Feb 16 '12 at 0:50
Answer updated with example –  David Carlisle Feb 16 '12 at 17:54
@geordie if headings want (say) center alignment then as usual you can specify that instead of the default column alignment with \multicolumn{1}{c}{my heading} –  David Carlisle Feb 5 '14 at 10:36

I thought I'd add my answer because it doesn't make use of any other packages (although I think using dcolumn is the easiest solution). What you can do is break each number column into two columns, one for the abscissa (left of the decimal) and one for the ordinate (right). Then, right align the first column, left align the second, and squeeze the space between them with @{}.

Specifically, this is option 1 in the question you linked.

I think the appropriate minimum solution is

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

-
Almost certainly. I've edited it appropriately. –  Warrick May 25 '12 at 16:59