[Tex/LaTex] Align along dot in tables

horizontal alignmenttables

Does anyone know how to align the figure along dot within the tabular environment? I would like the figures to be under each other sharing the decimal dot as a common point of alignment.

  \begin{table}[H]
    \caption{My table}
    \centering 
    \begin{tabular}{lccc}
    \toprule
            &  A            & B         & C         \\ \midrule
    D       & 0.00      & +171.00   &  +135.00   \\ 
    E               & +233.00   & +123.00   &  0.00   \\    
    F       & $-240.00$     & $-20.00$      & $-1590.00$ \\
    G               & $-56.00$      & +68.00        & $-95.00$   \\ \bottomrule
    \end{tabular}
    \end{table} 

Thank you very much for your help!

Best Answer

Use »siunitx« and its S column type.

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{caption}
\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}
  \begin{table}[!ht]
    \caption{My table}
    \centering
    \begin{tabular}{
      l
      S[table-format=-3.2]
      S[table-format=-3.2]
      S[table-format=-4.2]
    }\toprule
        & {A}     & {B}    & {C}      \\ \midrule
      D &    0.00 & 171.00 &   135.00 \\
      E &  233.00 & 123.00 &     0.00 \\
      F & -240.00 & -20.00 & -1590.00 \\
      G &  -56.00 &  68.00 &   -95.00 \\ \bottomrule
    \end{tabular}
  \end{table}
\end{document}

More formatting options are shown in the package manual.


enter image description here

Related Question