I want to color certain rows in a pgfplotstable lets say in red. I found a code snippet that colors the content of one cell. Below you can find an MWE in LaTeX beamer. The first table is done with pgfplots but only colors one cell. The second table is the target result, which is coded "traditionally". How can I achieve the target result in pgfplotstable?
Code: Select all
\documentclass[10pt,aspectratio=169]{beamer}
\usepackage[sfdefault]{noto}
\usepackage[T1]{fontenc}
\usefonttheme[onlymath]{serif} % math in serif but noto
\usefonttheme{professionalfonts} % math in default serif math font
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{pgfplotstable}
\usepackage{array}
\usepackage{booktabs}
\usepackage[table]{xcolor}
\usepackage{colortbl}
\usepackage[main=ngerman, english]{babel} % German date formats
\begin{document}
\begin{frame}[plain, fragile]
\setlength{\extrarowheight}{2pt}
\begin{center}
\begin{tikzpicture}
\node[inner sep=0pt, scale=1.0] {
\pgfplotstabletypeset[
col sep = &, row sep = \\,
columns/v/.style={column type=l|, string type, column name={},
postproc cell content/.append style={
/pgfplots/table/@cell content/.add={$\pmb}{$},
},
},
columns/x1/.style={column name={X},fixed, fixed zerofill=true,precision=2, dec sep align},
columns/x2/.style={column name={Y},fixed, fixed zerofill=true,precision=2, dec sep align},
every head row/.style={after row=\hline},
my special cell/.style={@cell content=\color{red}#1},
every row 1 column 0/.append style={
postproc cell content/.append code={%
\pgfkeysgetvalue{/pgfplots/table/@cell content}{\myTmpVal}%
\pgfkeysalso{my special cell/.expand once={\myTmpVal}}%
},
},
]{
v & x1 & x2 \\
{P}_1 & 43.46 & 28.77 \\
{P}_{1,2} & 70.68 & 29.79 \\
{P}_{2,1} & 85.23 & 2.13 \\
{P}_2 & 84.36 & 26.06 \\
{P}_{2,2} & 83.85 & 40.01 \\
{P}_{3,1} & 62.15 & 49.34 \\
{P}_3 & 32.94 & 52.91 \\
{P}_{3,2} & 11.95 & 32.81 \\
{P}_{4,1} & 0.02 & 4.73 \\
{P}_4 & 18.63 & 2.07 \\
{P}_{4,2} & 32.03 & 0.15 \\
{P}_{1,1} & 21.27 & 27.93 \\
{P}_1 & 43.46 & 28.77 \\
}
};
\end{tikzpicture}
\end{center}
\end{frame}
\begin{frame}[plain]
\begin{table}[h]
\centering
\begin{tabular}{l|cc}
& X & Y\\
\hline
$\pmb{P}_1$ & $43.46$ & $28.77$ \\
\textcolor{red}{$\pmb{P}_{1,2}$} & \textcolor{red}{$70.68$} & \textcolor{red}{$29.79$} \\
\textcolor{red}{$\pmb{P}_{2,1}$} & \textcolor{red}{$85.23$} & \textcolor{red}{$2.13$} \\
$\pmb{P}_2$ & $84.36$ & $26.06$ \\
\textcolor{red}{$\pmb{P}_{2,2}$} & \textcolor{red}{$83.85$} & \textcolor{red}{$40.01$} \\
\textcolor{red}{$\pmb{P}_{3,1}$} & \textcolor{red}{$62.15$} & \textcolor{red}{$49.34$} \\
$\pmb{P}_3$ & $32.94$ & $52.91$ \\
\textcolor{red}{$\pmb{P}_{3,2}$} & \textcolor{red}{$11.95$} & \textcolor{red}{$32.81$} \\
\textcolor{red}{$\pmb{P}_{4,1}$} & \textcolor{red}{$0.02$} & \textcolor{red}{$4.73$} \\
$\pmb{P}_4$ & $18.63$ & $2.07$ \\
\textcolor{red}{$\pmb{P}_{4,2}$} & \textcolor{red}{$32.03$} & \textcolor{red}{$0.15$} \\
\textcolor{red}{$\pmb{P}_{1,1}$} & \textcolor{red}{$21.27$} & \textcolor{red}{$27.93$} \\
$\pmb{P}_1$ & $43.46$ & $28.77$ \\
\end{tabular}
\end{table}
\end{frame}
\end{document}