pgfplotstable:使用“postproc 单元格内容”格式化时字符串替换不起作用

pgfplotstable:使用“postproc 单元格内容”格式化时字符串替换不起作用

看来,string replace={XXX}{replaced}如果我使用 ,那不起作用postproc cell content/.style={...}
我该怎么办?

在此处输入图片描述

\documentclass[a4paper]{article}
\usepackage{colortbl}
\usepackage{pgfplotstable}
\pgfplotsset{compat=newest}
\pgfplotstableread[col sep = semicolon, header=true]{
A;     B
111; aaa
222; XXX
333; ccc
444; ddd
555; XXX
}{\mytable}

\begin{document}

\section{With postproc cell content -- works not}
\pgfplotstabletypeset[string type,
columns/B/.style={
string replace={XXX}{replaced}, 
postproc cell content/.style={
  @cell content={\cellcolor{pink}\textcolor{blue}{##1}}   },
},
]{\mytable}

\section{Without postproc cell content -- works}
\pgfplotstabletypeset[string type,
columns/B/.style={
string replace={XXX}{replaced}, 
},
]{\mytable}
\end{document}

答案1

只需将字符串替换为以下内容的一部分postproc cell content

\documentclass[a4paper]{article}
\usepackage{colortbl}
\usepackage{pgfplotstable}
\pgfplotsset{compat=newest}
\pgfplotstableread[col sep = semicolon, header=true]{
A;     B
111; aaa
222; XXX
333; ccc
444; ddd
555; XXX
}{\mytable}

\ExplSyntaxOn
\cs_new_eq:NN \strifeq \str_if_eq:nnTF
\ExplSyntaxOff

\begin{document}

\section{With postproc cell content -- works not}
\pgfplotstabletypeset[string type,
columns/B/.style={
string replace={XXX}{replaced}, 
postproc cell content/.style={
  @cell content={\cellcolor{pink}\textcolor{blue}{##1}}   },
},
]{\mytable}

\section{Without postproc cell content -- works}
\pgfplotstabletypeset[string type,
columns/B/.style={
string replace={XXX}{replaced}, 
},
]{\mytable}

\section{With postproc cell content -- works}
\pgfplotstabletypeset[string type,
columns/B/.style={
postproc cell content/.style={
  @cell
  content={\cellcolor{pink}\textcolor{blue}{\strifeq{##1}{XXX}{replaced}{##1}}}},
},
]{\mytable}
\end{document}

在此处输入图片描述

相关内容