1

How can I use \pgfplotstablename in this case

\pgfplotstablegetelem{0}{[index]1}\of\TestTable instead of \TestTable?

enter image description here

MWE:

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

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

\begin{document}

\pgfplotstabletypeset[string type,
every head row/.style={output empty row},% no header 
% works  funny (with speech mark...)
columns/0/.style = {
string replace={0}{\pgfplotstablename\pgfplotsretval},
},
% works not
columns/1/.style = {
string replace={0}{%\pgfplotstablename % \pgfplotsretval
\pgfplotstablegetelem{0}{[index]1}\of\TestTable %<-- use tablename here
\pgfplotsretval
}
},
]{\TestTable}


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

Crossposting my answer from TeXwelt.de below.


When I inspect the definition of \pgfplotstablename using \show\pgfplotstablename, then I find in the log

> \pgfplotstablename=macro:
->\TestTable .

That menas the \pgfplotstablename expands to \TestTable in one step. Now we only have to find out how to force this one expansion step somehow. This can be done either with \edef or in LuaTeX and starting with TeX Live 2019 using \expanded.

\expanded{%
  \noexpand\pgfplotstablegetelem{0}{[index]1}\noexpand\of\expandafter\noexpand\pgfplotstablename
}%

The leading \noexpand in front of every macro inhibits expansion. The construction \expandafter\noexpand\pgfplotstablename leads TeX to jump over \noexpand and expanding \pgfplotstablename once. After that we have \noexpand\TestTable and all is good.

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

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

\begin{document}

\pgfplotstabletypeset[string type,
every head row/.style={output empty row},% keinen header anzeigen
% works  funny (with speech mark...)
columns/0/.style = {
  string replace={0}{\pgfplotstablename\pgfplotsretval},
},
% works not
columns/1/.style = {
  string replace={0}{%\pgfplotstablename % \pgfplotsretval
    \expanded{%
      \noexpand\pgfplotstablegetelem{0}{[index]1}\noexpand\of\expandafter\noexpand\pgfplotstablename
    }%
    \pgfplotsretval
  }
},
]{\TestTable}

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

enter image description here

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.