LaTex错误:度量单位(已插入pt)

问题描述 投票:0回答:1

我在LaTex中遇到了这个问题。尽管我知道错误消息的含义,但是我不知道如何解决任务中的错误。

\newcommand*{\MinNumber}{0}%
\newcommand*{\MaxNumber}{1.2}%
\pgfmathsetmacro{\MidNumber}{(0.8}%
\def\test#1{\ifdim#1pt>\MidNumber\textcolor{gray!70}{#1}\else{#1}\fi}
\newcommand{\ApplyGradient}[2]{\centering %
  \pgfmathsetmacro{\PercentColor}{100.0*(#1-\MinNumber)/(\MaxNumber-\MinNumber)}%
  \edef\x{\noexpand\cellcolor{black!\PercentColor}}\x\test{#1}
}
\newcolumntype{R}{>{\collectcell\ApplyGradient}p{1.1cm}<{\endcollectcell}}
\newcolumntype{S}{>{\collectcell\ApplyGradient}p{0.6cm}<{\endcollectcell}}
%
\begin{table}[!ht]
\centering
\small
% \renewcommand{\arraystretch}{0.9}
% \begin{adjustbox}{width=0.8\textwidth}
\begin{tabular}{>{\centering}p{1.3cm}|>{\centering}p{0.9cm}|R R R R 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}$}  & \multicolumn{1}{c} {$-\ang{40}$} \\ \midrule
            & $\ang{40}$    & 0.52  & 0.44  & 0.27  & 0.10  & -0.01 \\
            & $\ang{20}$    & 0.47  & 0.49  & 0.35  & 0.19  & 0.07 \\
spider9     & $\ang{0}$     & 0.25  & 0.47  & 0.63  & 0.46  & 0.24 \\
            & $-\ang{20}$   & 0.05  & 0.17  & 0.35  & 0.55  & 0.54 \\
            & $-\ang{40}$   & 0.0   & 0.05  & 0.21  & 0.47  &  0.77 \\ 
\midrule
            & $\ang{40}$   & 0.75  & 0.69  & 0.40  & 0.17  & 0.04 \\
            & $\ang{20}$   & 0.72  & 0.82  & 0.59  & 0.30  & 0.10 \\
gecko7      & $\ang{0}$    & 0.31  & 0.65  & 1.06  & 0.96  & 0.56 \\
            & $-\ang{20}$  & 0.16  & 0.45  & 0.86  & 1.18  & 0.98 \\
            & $-\ang{40}$  & 0.03  & 0.15  & 0.40  & 0.74  & 0.96 \\ 
\midrule
            & $\ang{40}$   & 1.09  & 0.75  & 0.39  & 0.14  & 0.02 \\
            & $\ang{20}$   & 0.54  & 0.55  & 0.33  & 0.15  & 0.04 \\
babyA       & $\ang{0}$    & 0.29  & 0.58  & 0.88  & 0.74  & 0.42 \\
            & $-\ang{20}$  & 0.18  & 0.47  & 0.85  & 1.09  & 0.71 \\
            & $-\ang{40}$  & 0.02  & 0.11  & 0.33  & 0.65  & 0.91 \\
\bottomrule            
\end{tabular}
%
\begin{tabular}{p{0.4cm} S}
& 0.0 \\
& 0.1 \\
& 0.2 \\
& 0.3 \\
& 0.4 \\
& 0.5 \\
& 0.6 \\
& 0.7 \\
& 0.8 \\
& 0.9 \\
& 1.0 \\
& 1.1 \\
& 1.2 \\
\end{tabular}
% \end{adjustbox}
\caption{Robustness of the top learned controllers for different directions in the real world. 
The data shows the fitness that the top controllers of three robots in 5 directions (the second column) perform in another directions (the first row). 
The fitness value in a cell is averaged over three controller and three repetitions for each controller. 
The dark and light color represent the high and low fitness value respectively.}
\label{tab:robustness}
\end{table}

该表如图所示:enter image description here

但是我有很多错误,例如:

非法计量单位(已插入磅)。

\保护l.1545&$ \ ang {40} $&0.52&0.44&0.27&0.10&-0.01 \尺寸可以以em,ex,in,pt,pc,cm,mm,dd,cc,nd,nc,bp或sp;但是你是一个新的!我假设您要说pt,代表打印机的观点。要从此错误中正常恢复,最好执行以下操作:删除错误的单元;例如,输入“ 2”以删除两个字母。 (请参阅TeXbook的第27章。)

!非法计量单位(已插入pt)。\保护l.1545 ...&$ \ ang {40} $&0.52&0.44&0.27&0.10&-0.01 \尺寸可以以em,ex,in,pt,pc,cm,mm,dd,cc,nd,nc,bp或sp;但是你是一个新的!我假设您要说pt,代表打印机的观点。要从此错误中正常恢复,最好执行以下操作:删除错误的单元;例如,输入“ 2”以删除两个字母。 (请参阅TeXbook的第27章。)

您能帮我解决这个问题吗?谢谢!

latex
1个回答
0
投票

以下是一些注意事项:

  • 虽然\MinNumber定义为0,但是您的数字小于表(-0.01)中的数字。

  • 如果要对dim尺寸(\ifdim <dimA><relation><dimB>)进行测试,则需要确保<dimA><dimB>均为尺寸。根据您的情况,您有

    \ifdim#1pt>\MidNumber
    

    并且\MidNumber显然不是尺寸。它只是一个数字(0.8)。这是问题的主要原因。

  • [\ApplyGradient应该只接受一个参数,不能接受两个。

  • booktabs中将booktabs与垂直规则一起使用很尴尬。他们并没有真正的需求。我将它们保留在输出中,但是您不需要它们。

tabular

enter image description here
© www.soinside.com 2019 - 2024. All rights reserved.