4

Output table from the MWE:

Sample table with problems

Problems:

1) When the color of the numeric values are changed we also want the color of the decimal point to change.

2) We want the null entry (last entry in column 1) to be an empty field; instead the alignment character . appears.

MWE

\documentclass{article}
\usepackage{color}
\begin{document}
  \begin{table}
    \begin{tabular}{r@{.}lr@{.}l}
      \color{red}{1} & \color{red}{0} & 3 & 1 \\
      2 & 1 & 4 & 4 \\
      &&      5 & 7
    \end{tabular}
  \end{table}
\end{document}

Distribution: TeXLive - 2015

Application: TeXShop 3.58

8

Use the siunitx package, you will have a much simpler code:

\documentclass{article}
\usepackage{color}
\usepackage{siunitx}

\begin{document}

  \begin{table}
\sisetup{table-number-alignment=center}
    \begin{tabular}{S[table-format=1.5]S[table-format=-1.1]}
      \color{red}1.0 & 3.1 \\
      2.12346 & -4.4 \\
      & 5.7
    \end{tabular}
  \end{table}
\end{document} 

enter image description here

3
  • The answer looks great. However when the second row is replaced with 2.12346 & -4.4 disaster results. Can we restore the flexibility of r@{.}l? – dantopa Nov 12 '15 at 0:13
  • Yes of course.. You have to specify the ‘maximum’ format in each column, as an optional argument to the S column type. Please see my updated answer. – Bernard Nov 12 '15 at 0:26
  • What a great solution. Much easier to use. – dantopa Nov 12 '15 at 22:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.