27

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}}
\hline \hline \addlinespace
& (1)  \\  
Variable Name & 0.1234566  \\
& (0.1234566) \\
\hline \hline \addlinespace
 \end{tabularx}
\begin{tablenotes}
\vspace{0.1cm}
\footnotesize{

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

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

\end{document}

4 Answers 4

27

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}

enter image description here

1
  • 3
    It may be worth nothing that dcolumn is included in the memoir package. Mar 6, 2012 at 15:13
24

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}

enter image description here

8
  • 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, 2012 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. Feb 16, 2012 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, 2012 at 0:50
  • 1
    Answer updated with example Feb 16, 2012 at 17:54
  • 2
    @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} Feb 5, 2014 at 10:36
15

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}
1
  • 1
    Almost certainly. I've edited it appropriately.
    – Warrick
    May 25, 2012 at 16:59
0

A simple workaround for when you don't have too many entries (or if you don't mind auto-substituting a piece of text into every line) is to pad with \phantom{} (which has the effect of taking up as much space as its argument would have taken, but will not show anything). For example:

\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{rrr}
& (1) & (2) \\  
\midrule
Variable Name & 98.1234567           & 1234.56 \\
              & (0.6789)\phantom{67} &  (54.3) \\
\bottomrule
\end{tabular}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .