我想创建一个条件,其中小于 7 的值以红色表示,大于或等于 7 的值以蓝色表示。
我想要如下所示的结果:
遵循我的 MWE。
\documentclass[12pt,a4paper]{article}
\usepackage[brazil]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[pdftex]{color}
\usepackage{longtable}
\usepackage{spreadtab}
\begin{document}
\pagestyle{empty}
\centering
\begin{spreadtab}{{longtable}{c c c c c c}}
\hline
@ {\bf Number} & @ {\bf 1º Exam} & @ {\bf 2º Exam} & @ {\bf Mean} & @ {\bf Final} & @ {\bf Situation} \\
\hline
\rowcolor{gray!25}
@ 18101610 & 7 & 8.5 & (b2+c2)/2 & - & \\
@ 18103839 & 6 & 4.3 & (b3+c3)/2 & 7 & \\
\rowcolor{gray!25}
@ 18101547 & 5.4 & 3.5 & (b4+c4)/2 & 6 & \\
@ 18100204 & 7 & 8 & (b5+c5)/2 & - & \\
\rowcolor{gray!25}
@ 14101294 & 9 & 10 & (b6+c6)/2 & - & \\
@ 18101505 & 3.7 & 1.5 & (b7+c7)/2 & - & \\
\hline
\end{spreadtab}
\end{document}
其他问题已经解决了这个问题,但在我看来,\usepackage[table]{xcolor}
与相冲突\usepackage{collcell,xfp}
。条件正在改变所有单元格的颜色,甚至文本也变成了彩色。
\documentclass[12pt,a4paper]{article}
\usepackage[brazil]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[pdftex]{color}
\usepackage{collcell, xfp}
\usepackage{longtable}
\usepackage{spreadtab}
\begin{document}
\newcommand{\fmtnum}[1]{%
\ifnum\fpeval{#1 < 7} = 1
\textcolor{red}{$#1$}%
%\else
%\ifnum\fpeval{#1 < 0.5} = 1
%\textcolor{green}{$#1$}%
\else
\textcolor{blue}{$#1$}%
%\fi
\fi
}
\centering
\begin{tabular}{ *{6}{>{\collectcell\fmtnum}c<{\endcollectcell}}}
\hline
{\bf Number} & {\bf 1º Exam} & {\bf 2º Exam} & {\bf Mean} & {\bf Final} & {\bf Situation} \\
\hline
\rowcolor{gray!25}
18101610 & 1 & 2 & 1.5 & & \\
18103839 & 4 & 7.5 & 5.75 & 7 & \\
\rowcolor{gray!25}
18101547 & 5.4 & 3.5 & 4.45 & 6 & \\
18100204 & 7 & 8 & 7.5 & - & \\
\rowcolor{gray!25}
14101294 & 9 & 10 & 9.5 & - & \\
18101505 & 3.7 & 1.5 & 2.6 & - & \\
\hline
\end{tabular}
\end{document}
类似问题:
https://stackoverflow.com/questions/52123278/number-color-according-to-its-value-in-latex