LaTex errors: unit of measure (pt inserted)

Here are some considerations:

  • While \MinNumber is defined to be 0, you have a number that is smaller than that in the table (-0.01).
  • If you’re performing a test on dimensions (\ifdim <dimA><relation><dimB>) you need to make sure both <dimA> and <dimB> are dimensions. In your case you have\ifdim#1pt>\MidNumber and \MidNumber is clearly not a dimension. It is just a number (0.8). That’s the main cause of the problem.
  • \ApplyGradient should only take a single argument, not two.
  • It’s awkward to use booktabs together with vertical rules in a tabular. There’s no real need for them; I’ve kept them in the output, but you don’t need them.
\documentclass{article}

\usepackage[margin=1in]{geometry}% Just for this example
\usepackage[table]{xcolor}
\usepackage{booktabs,collcell,xfp}

\newcommand*{\ang}[2]{#1^\circ}
\newcommand*{\MinNumber}{-0.01}%
\newcommand*{\MaxNumber}{1.2}%
\newcommand*{\MidNumber}{0.8}%

\newcommand{\test}[2]{\ifdim#1pt>\MidNumber pt\textcolor{gray!70}{#1}\else #1\fi}

\newcommand{\ApplyGradient}[2]{\centering %
  \edef\x{\noexpand\cellcolor{black!\fpeval{100*(#1-\MinNumber)/(\MaxNumber-\MinNumber)}}}\x\test{#1}
}
\newcolumntype{R}{>{\collectcell\ApplyGradient}p{1.1cm}<{\endcollectcell}}
\newcolumntype{S}{>{\collectcell\ApplyGradient}p{0.6cm}<{\endcollectcell}}
%

\begin{document}

\begin{table}
  \centering
  \begin{tabular}{
    >{\centering}p{1.3cm} |
    >{\centering}p{0.9cm} |
    *{5}{R}
  }
    \multicolumn{2}{c}{testing in$\rightarrow$} & 
      \multicolumn{1}{c}{$\ang{40}$} & 
      \multicolumn{1}{c}{$\ang{20}$} & 
      \multicolumn{1}{c}{$\ang{0}$}  & 
      \multicolumn{1}{c}{$-\ang{20}$} & 

Leave a Comment