Automatically formatting table cells, with Latex

Over time I needed to format tables based on numerical values, rather than doing it manually – as before – I recently took the time to automate this annoying task.

That is why I created this macro for coloring based on speedups:

\newcommand{\speedupCell}[2]{\pgfmathparse{#1<0.95}%
\ifnum\pgfmathresult=1%
    \cellcolor{red!10}\pgfmathprintnumber[fixed,fixed zerofill,precision=#2]{#1}%
\else%
    \pgfmathparse{#1<1.05}%
    \ifnum\pgfmathresult=1%
        \cellcolor{gray!10}\pgfmathprintnumber[fixed,fixed zerofill,precision=#2]{#1}%
    \else%
        \cellcolor{green!10}\pgfmathprintnumber[fixed,fixed zerofill,precision=#2]{#1}%
    \fi%
\fi%
}

It assumes that everything point between 0.95 and 1.05 is noise and marks it grey.

This macro requires these includes to be added to the preamble:

\usepackage[table]{xcolor}
\usepackage{tikz}

And, one can use it like that:

\begin{tabular}{l r}
    System & Speedup \\
    \hline
    \emph{A} & \speedupCell{0.5}{2} \\
    \emph{B} & \speedupCell{9}{2} \\
    \emph{C} & \speedupCell{0.97}{2} \\
\end{tabular}

You can find an example document at https://www.overleaf.com/read/xzctstmfkmfh#d83096