2

I need to align the text in columns by decimals in the numbers. However the numbers go together with text so I can not simple use dcolumn package in 5th column as in the 1st one. If I split to more columns - the spaces are too big.

And I can not use siunitx since I have to use Slunits and they just don't work together.

The code:

\documentclass[12pt]{article}

\usepackage{multirow}
\usepackage{array}
\newcommand{\sta}{\mathrm{(stat.)}}
\newcommand{\sys}{\mathrm{(sys.)}}

\usepackage{dcolumn}
\newcolumntype{d}[1]{D{.}{.}{#1} }

\begin{document}
    \begin{table}
        \begin{center}
            \begin{tabular}{|d{1.3}cd{1.3}| d{3.4} l | l l |}%{|lcl|ll|ll|}
                \hline
                \multicolumn{3}{|c|}{\strut$x$ range}    
                & \multicolumn{2}{c|}{  measurement 1 (units)} 
                & \multicolumn{2}{c|}{  measurement 2 (units)} \\
                \hline
                0.000 &--& 0.005   &   452.4444 & $  \pm$   43.4444$\sta\,\pm$  23.4444$\,\sys$ &     87.4444     & $  \pm$    7.4444$\,\sta$ \\
                0.025 &--& 0.010   &   645.4444 & $  \pm$   45.4444$\sta\,\pm$  42.4444$\,\sys$ &    410.4444     & $  \pm$   40.4444$\,\sta$ \\
                0.010 &--& 0.015   &   458.4444 & $  \pm$   45.4444$\sta\,\pm$  36.4444$\,\sys$ &     79.4444     & $  \pm$    4.4444$\,\sta$ \\
                0.025 &--& 0.025   &   167.4444 & $  \pm$   18.4444$\sta\,\pm$  14.1747$\,\sys$ &     46.4444     & $  \pm$    4.4444$\,\sta$ \\
                0.045 &--& 0.030   &    52.4444 & $  \pm$    4.4444$\sta\,\pm$   4.4444$\,\sys$ &     18.7175     & $  \pm$    4.4444$\,\sta$ \\
                0.040 &--& 0.090   &     4.4444 & $  \pm$    4.4444$\sta\,\pm$   4.4444$\,\sys$ &      4.4444     & $  \pm$    4.4444$\,\sta$ \\
                \hline
            \end{tabular}
        \end{center}
        \caption{text.}
    \end{table}
\end{document}

enter image description here

2
  • 1
    if i were doing this, i'd take a "lazy" approach -- insert spaces the width of a digit in appropriate places to align the digits. \newcommand{\0}(\phantom{0}} gives a command that is easy to remember. Mar 12, 2016 at 13:58
  • @barbara-beeton thank you! it actually solved my problem
    – greyxray
    Mar 12, 2016 at 14:12

1 Answer 1

4

I would recommend that you provide more information in the argument of tabular about the structure of the table. That way, the body of the tabular environment need contain only numbers.

enter image description here

\documentclass[12pt]{article}

\usepackage{dcolumn}
\newcolumntype{d}[1]{D{.}{.}{#1} }

\begin{document}

\begin{table}
\centering
\begin{tabular}{|d{1.3} @{--} d{1.3} | 
                 d{3.4} @{${}\pm{}$} 
                 d{2.4} @{(stat.)${}\pm{}$} 
                 d{2.4} @{(sys.)\hspace{\tabcolsep}} |
                 d{3.4} @{${}\pm{}$} 
                 d{2.4} @{(stat.)\hspace{\tabcolsep}} |}
\hline
  \multicolumn{2}{|c|}{\strut$x$ range}
& \multicolumn{3}{ c|}{measurement 1 (units)} 
& \multicolumn{2}{ c|}{measurement 2 (units)} \\
\hline
0.000 & 0.005 & 452.4444 & 43.4444 & 23.4444 & 87.4444 & 7.4444 \\
0.025 & 0.010 & 645.4444 & 45.4444 & 42.4444 &410.4444 & 40.4444 \\
0.010 & 0.015 & 458.4444 & 45.4444 & 36.4444 & 79.4444 & 4.4444 \\
0.025 & 0.025 & 167.4444 & 18.4444 & 14.1747 & 46.4444 &  4.4444 \\
0.045 & 0.030 &  52.4444 &  4.4444 &  4.4444 & 18.7175 & 4.4444 \\
0.040 & 0.090 &   4.4444 &  4.4444 &  4.4444 &  4.4444 & 4.4444 \\
\hline
\end{tabular}
\caption{text.}
\end{table}
\end{document}

You must log in to answer this question.

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