2

How can I replace e.g. the 'zeros' by the cell content of the current header?

enter image description here

\documentclass[border=5pt]{standalone}
\usepackage{pgfplotstable}

\pgfplotstableread{
A   B
1   2
0   2
1   0
0   2
0   2
1   0
}\test

\begin{document}

\pgfplotstabletypeset[string type,
%string replace={0}{aaa}
]{\test}

\end{document}
  • You can get the header elements by transposing your table, then using \pgfplotstablegetelem and \pgfplotsretval. – joseldsm Nov 15 '18 at 10:40
2

Suggestion using expl3:

\documentclass[border=5pt]{standalone}
\usepackage{pgfplotstable}
\pgfplotsset{compat=newest}
\pgfplotstableread{
A   B
1   2
0   2
1   0
0   2
0   2
1   0
}\test
\pgfplotstablegetcolsof{\test}
\pgfmathtruncatemacro\colmax{\pgfplotsretval-1}

\usepackage{expl3}
\ExplSyntaxOn
\int_step_inline:nnnn
  {0}{1}{\colmax}
  {
    \pgfplotstablegetcolumnnamebyindex{#1}\of\test\to\colname
    \pgfplotstablemodifyeachcolumnelement{\colname}\of\test\as\cell
      {\pgfmathparse{\cell==0?"\colname":\cell}\xdef\cell{\pgfmathresult}}
  }
\ExplSyntaxOff

\begin{document}
\pgfplotstabletypeset[string type]{\test}
\end{document}

enter image description here

0

Possible:

\pgfplotsinvokeforeach{0,1} {%
\pgfplotstableset{
columns/#1/.style = {
string replace={0}{\pgfplotstablegetelem{0}{[index]#1}\of\test \pgfplotsretval}
}}}%

But this is not so nice, because I have to say \of\test, so this does not work as a general style...

enter image description here

\documentclass[border=5pt]{standalone}
\usepackage{pgfplotstable}

\pgfplotstableread[header=false]{
A   B
1   2
0   2
1   0
0   2
0   2
1   0
}\test

\begin{document}

% Nullen ersetzen
\pgfplotsinvokeforeach{0,1} {%
\pgfplotstableset{
columns/#1/.style = {
string replace={0}{\pgfplotstablegetelem{0}{[index]#1}\of\test \pgfplotsretval}
}}}%

\pgfplotstabletypeset[string type,
skip rows between index={0}{1},% Benennungszeile ausblenden
every head row/.style={output empty row},% keinen header anzeigen
]{\test}

%Test:  \pgfplotstablegetelem{0}{[index]0}\of\test \pgfplotsretval
%\pgfplotstablegetelem{0}{[index]1}\of\test \pgfplotsretval
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.