12

I use pgfplotstable to generate tables to be included in online submission to journals. I would like to make my paper independant of pgfplotsable because compilation of the document is made online with an obsolete LaTeX distribution and clumsy packages handling.

I already asked a question to that effect (see this question) but I am now facing a more complicated case. With this, I learned about the outfile= option of the \pgfplotstabletypeset command which write the tables into a file.

I am using some features of pgfplotstable to replace the number in the table by symbols (inspired by this question). Here is an eample similar to my actual code:

\documentclass{article}
\usepackage{pgfplotstable}

\begin{document}
\pgfplotstableset{symbol column/.style={column type=c,
    postproc cell content/.style={
      /pgfplots/table/@cell content={}{%
        \pgfmathparse{int(less(##1, 0.01))}
        \ifnum\pgfmathresult=1
        *
        \else
            \pgfmathparse{int(less(##1, .1))}
            \ifnum\pgfmathresult=1
            **
            \else
                \pgfmathparse{int(less(##1,1))}
                \ifnum\pgfmathresult=1
                ***
                \else
                { }
                \fi
            \fi
        \fi
      },
    },
}}





\pgfplotstabletypeset[outfile=output_table.tex,
columns/A/.style={symbol column},
columns/B/.style={symbol column},
]
{%
A B
.001 5
.1 .5
.2  .005
1.7 22
}
\end{document}

The output file looks like this:

\begin {tabular}{cc}%
A&B\\%
{}{\pgfmathparse {int(less(.001, 0.01))} \ifnum \pgfmathresult =1 * \else \pgfmathparse {int(less(.001, .1))} \ifnum \pgfmathresult =1 ** \else \pgfmathparse {int(less(.001,1))} \ifnum \pgfmathresult =1 *** \else { } \fi \fi \fi }&{}{\pgfmathparse {int(less(5, 0.01))} \ifnum \pgfmathresult =1 * \else \pgfmathparse {int(less(5, .1))} \ifnum \pgfmathresult =1 ** \else \pgfmathparse {int(less(5,1))} \ifnum \pgfmathresult =1 *** \else { } \fi \fi \fi }\\%
{}{\pgfmathparse {int(less(.1, 0.01))} \ifnum \pgfmathresult =1 * \else \pgfmathparse {int(less(.1, .1))} \ifnum \pgfmathresult =1 ** \else \pgfmathparse {int(less(.1,1))} \ifnum \pgfmathresult =1 *** \else { } \fi \fi \fi }&{}{\pgfmathparse {int(less(.5, 0.01))} \ifnum \pgfmathresult =1 * \else \pgfmathparse {int(less(.5, .1))} \ifnum \pgfmathresult =1 ** \else \pgfmathparse {int(less(.5,1))} \ifnum \pgfmathresult =1 *** \else { } \fi \fi \fi }\\%
{}{\pgfmathparse {int(less(.2, 0.01))} \ifnum \pgfmathresult =1 * \else \pgfmathparse {int(less(.2, .1))} \ifnum \pgfmathresult =1 ** \else \pgfmathparse {int(less(.2,1))} \ifnum \pgfmathresult =1 *** \else { } \fi \fi \fi }&{}{\pgfmathparse {int(less(.005, 0.01))} \ifnum \pgfmathresult =1 * \else \pgfmathparse {int(less(.005, .1))} \ifnum \pgfmathresult =1 ** \else \pgfmathparse {int(less(.005,1))} \ifnum \pgfmathresult =1 *** \else { } \fi \fi \fi }\\%
{}{\pgfmathparse {int(less(1.7, 0.01))} \ifnum \pgfmathresult =1 * \else \pgfmathparse {int(less(1.7, .1))} \ifnum \pgfmathresult =1 ** \else \pgfmathparse {int(less(1.7,1))} \ifnum \pgfmathresult =1 *** \else { } \fi \fi \fi }&{}{\pgfmathparse {int(less(22, 0.01))} \ifnum \pgfmathresult =1 * \else \pgfmathparse {int(less(22, .1))} \ifnum \pgfmathresult =1 ** \else \pgfmathparse {int(less(22,1))} \ifnum \pgfmathresult =1 *** \else { } \fi \fi \fi }\\%
\end {tabular}%

which depends upon pgf for the \pgfmathparse and associated commands.

Is there a way to circumvent this without manually editing the table or using external program

  • 2
    You assign executable code into each cell. However, you could also assign the result of your evaluation into the cell - which would do what you want. Something similar is done in tex.stackexchange.com/questions/136331/…; perhaps you could do the same. The idea would be to assemble your stuff into a macro, and then use \pgfkeyslet to copy the content of that macro into the output table (as in the other question). – Christian Feuersänger Dec 2 '13 at 19:46
  • @ChristianFeuersänger -- Thank you for your input. Do you have an idea of how to simplify the code I came up with using your suggestion? I posted it in an answer. Feel free to edit or take it over in a new answer and I will delete mine. – Alfred M. Dec 3 '13 at 10:57
10

In general it might be hard but here you are only using pgfmath for an inequality test which is a sledgehammer you can avoid:

\documentclass{article}
\usepackage{pgfplotstable}



\begin{document}
\pgfplotstableset{symbol column/.style={column type=c,
    postproc cell content/.style={
      /pgfplots/table/@cell content={}{%
        \ifdim##1pt <0.01pt
        *
        \else
        \ifdim##1pt <0.1pt
            **
            \else
        \ifdim##1pt <1pt
                ***
                \else
                { }
                \fi
            \fi
        \fi
      },
    },
}}





\pgfplotstabletypeset[outfile=output_table.tex,
columns/A/.style={symbol column},
columns/B/.style={symbol column},
]
{%
A B
.001 5
.1 .5
.2  .005
1.7 22
}
\end{document}

produces

\begin {tabular}{cc}%
A&B\\%
{}{\ifdim .001pt <0.01pt * \else \ifdim .001pt <0.1pt ** \else \ifdim .001pt <1pt *** \else
 { } \fi \fi \fi }&{}{\ifdim 5pt <0.01pt * \else \ifdim 5pt <0.1pt ** \else \ifdim 5pt <1pt
 *** \else { } \fi \fi \fi }\\%
{}{\ifdim .1pt <0.01pt * \else \ifdim .1pt <0.1pt ** \else \ifdim .1pt <1pt *** \else { } \
fi \fi \fi }&{}{\ifdim .5pt <0.01pt * \else \ifdim .5pt <0.1pt ** \else \ifdim .5pt <1pt **
* \else { } \fi \fi \fi }\\%
{}{\ifdim .2pt <0.01pt * \else \ifdim .2pt <0.1pt ** \else \ifdim .2pt <1pt *** \else { } \
fi \fi \fi }&{}{\ifdim .005pt <0.01pt * \else \ifdim .005pt <0.1pt ** \else \ifdim .005pt <
1pt *** \else { } \fi \fi \fi }\\%
{}{\ifdim 1.7pt <0.01pt * \else \ifdim 1.7pt <0.1pt ** \else \ifdim 1.7pt <1pt *** \else { 
} \fi \fi \fi }&{}{\ifdim 22pt <0.01pt * \else \ifdim 22pt <0.1pt ** \else \ifdim 22pt <1pt
 *** \else { } \fi \fi \fi }\\%
\end {tabular}%
2

Following Christian's comment, I wrote the following code:

\documentclass{article}
\usepackage{pgfplotstable}

\begin{document}
\newcommand{\filtercode}{%
       \pgfmathparse{int(less(\cellvalue, 0.01))}%
       \ifnum\pgfmathresult=1 %
       \edef\cellvalue{x}%
       \else
            \pgfmathparse{int(less(\cellvalue, .1))}%
            \ifnum\pgfmathresult=1 %
            \edef\cellvalue{xx}%
            \else
                \pgfmathparse{int(less(\cellvalue,1))}%
                \ifnum\pgfmathresult=1 %
                \edef\cellvalue{xxx}%
                \else
               \edef\cellvalue{Z}%
                \fi
            \fi
       \fi
        \toks0=\expandafter{\cellvalue}%
        \edef\value{{}\the\toks0}%
        %\show\value
        \pgfkeyslet{/pgfplots/table/create col/next content}\value
}

\pgfplotstableset{%
  create on use/AA/.style={create col/assign/.code={%
      \getthisrow{A}\cellvalue\filtercode}},%
  create on use/BB/.style={create col/assign/.code={%
      \getthisrow{B}\cellvalue\filtercode}},%
}

\pgfplotstabletypeset[outfile=output_table.tex,
columns/AA/.style={string type, column type=c},
columns/BB/.style={string type, column type=c},
    % debug,
    columns={AA, BB}
]
{%
A B
.001 5
.0001 .5
.2  .005
1.7 22
}

\end{document}

It produce this output

\begin {tabular}{cc}%
AA&BB\\%
{}x&{}Z\\%
{}x&{}xxx\\%
{}xxx&{}x\\%
{}Z&{}Z\\%
\end {tabular}%

which is what I was looking for.

  • 1
    Thats a good solution. I do not know what is wrong with the asterisks, but it seems to be working if you write \edef\value{{}\the\toks0}. Apparently, they have some special meaning in tabulars (?). – Christian Feuersänger Dec 3 '13 at 20:07
  • 1
    There is one issue, though: you should termine all lines with % to suppress spurious white spaces. TeX is, unfortunately, non-trivally picky about them. As a rule-of-thumb, you should always place % after } if that is at the end-of-line. But: leave a space after numbers like \ifnum<xxx>=1 %. If you keep the spaces, you will observe too much whitespace before your tables. – Christian Feuersänger Dec 3 '13 at 20:09
  • If you like to extract a style: write \pgfplotstableset{create on use/AA/.style={......}} into your preamble; that should do the job. Any key assignment can be moved into some "shared" place; it'll be active until it is overridden by some other setting. – Christian Feuersänger Dec 3 '13 at 20:10
  • @ChristianFeuersänger: I edited the code following your last comment about “extracting a style”. There is still some copy and paste to do but it is much more streamlined. – Alfred M. Dec 5 '13 at 12:39

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.