2

I need to highlight the elements in each rows. I use the package pgfplotstable, but it doesn't work. And gives me an error.

\documentclass[]{article}
\usepackage{pgfplotstable}
    \pgfplotsset{compat=newest}     % 

\begin{document}


\newcommand{\findmax}[3]{
    \pgfplotstablevertcat{\datatable}{#1}
    \pgfplotstablecreatecol[
    create col/expr={%
    \pgfplotstablerow
    }]{rownumber}\datatable
    \pgfplotstablesort[sort key={#2},sort cmp={float >}]{\sorted}{\datatable}%
    \pgfplotstablegetelem{0}{rownumber}\of{\sorted}%
    \pgfmathtruncatemacro#3{\pgfplotsretval}
    \pgfplotstableclear{\datatable}
}

\newcommand{\findmin}[3]{
    \pgfplotstablevertcat{\datatable}{#1}
    \pgfplotstablecreatecol[
      create col/expr={%
    \pgfplotstablerow
    }]{rownumber}\datatable
    \pgfplotstablesort[sort key={#2},sort cmp={float <}]{\sorted}{\datatable}%
    \pgfplotstablegetelem{0}{rownumber}\of{\sorted}%
    \pgfmathtruncatemacro#3{\pgfplotsretval}
    \pgfplotstableclear{\datatable}
}

\pgfplotstableset{
    highlight col max/.code 2 args={
        \findmax{#1}{#2}{\maxval}
        \edef\setstyles{\noexpand\pgfplotstableset{
                every row \maxval\noexpand\space column #2/.style={
                    postproc cell content/.append style={
                        /pgfplots/table/@cell content/.add={$\noexpand\bf}{$}
                    },
                }
            }
        }\setstyles
    },
    highlight col min/.code 2 args={
        \findmin{#1}{#2}{\minval}
        \edef\setstyles{\noexpand\pgfplotstableset{
                every row \minval\noexpand\space column #2/.style={
                    postproc cell content/.append style={
                        /pgfplots/table/@cell content/.add={\noexpand\color{red}$\noexpand\bf}{$}
                    },
                }
            }
        }\setstyles
    },
    highlight row max/.code 2 args={
        \pgfmathtruncatemacro\rowindex{#2-1}
        \pgfplotstabletranspose{\transposed}{#1}
        \findmax{\transposed}{\rowindex}{\maxval}
        \edef\setstyles{\noexpand\pgfplotstableset{
                every row \rowindex\space column \maxval\noexpand/.style={
                    postproc cell content/.append style={
                        /pgfplots/table/@cell content/.add={$\noexpand\bf}{$}
                    },
                }
            }
        }\setstyles
    },
    highlight row min/.code 2 args={
        \pgfmathtruncatemacro\rowindex{#2-1}
        \pgfplotstabletranspose{\transposed}{#1}
        \findmin{\transposed}{\rowindex}{\maxval}
        \edef\setstyles{\noexpand\pgfplotstableset{
                every row \rowindex\space column \maxval\noexpand/.style={
                    postproc cell content/.append style={
                        /pgfplots/table/@cell content/.add={\noexpand\color{red}$\noexpand\bf}{$}
                    },
                }
            }
        }\setstyles
    },
}

\begin{table}[ht]
\begin{center}
\pgfplotstableread[col sep=comma]{
N1, N2,a,b,c,a, b, c
x1,x2,1,3,5, 2,4,6 
y1,y2,2,6,8,3,7,1 
z1,z2,1,2,7,8,7,6
}\data
\pgfplotstabletypeset[
columns/N1/.style={string type},
   columns/N2/.style={column type={l|}, string type},
   columns/c/.style={column type={l|}, string type},
    every head row/.style={before row=\hline, after row=\hline},
    every last row/.style={after row=\hline},
    empty cells with={\ensuremath{-}},
    highlight row max ={\data}{1},
    highlight row max ={\data}{2},
    highlight row max ={\data}{3},
]{\data}
\end{center}
\caption{My table.}
\label{tab:results}
\end{table}

\end{document}

How to use pgfplotstable highlight 5 and 6 in the first row, 8, 7 in the second row and 7, 8 in the third row?

Torbjørn T.
  • 206,688
when
  • 21
  • 1

0 Answers0