1

I'm currently loading a table via '\pgfplotstabletypeset` and I found out that I can manipulate the header like this:

\documentclass{article}
\usepackage{pgfplotstable}
\usepackage{filecontents}

\begin{filecontents*}{data.csv}
    a b c d
    1 4 5 1
    2 3 1 5
    3 5 6 1
    4 1 4 9
    5 3 4 7
\end{filecontents*}

\begin{document}
    \pgfplotstabletypeset[
        assign column name/.style= {%
            /pgfplots/table/column name={#1 $\left[\frac{1}{\textrm{s}}\right]$}
        },
    ] {data.csv}
\end{document}

Now I have come to a point where I only want to change the column names of columns > 0 (so the first one should stay just the way it is). However all my attempts to create a conditional statement that uses \pgfplotstablecol in order to retrieve the column index have failed.

What I want is something like this: \documentclass{article} \usepackage{pgfplotstable} \usepackage{filecontents}

\begin{filecontents*}{data.csv}
    a b c d
    1 4 5 1
    2 3 1 5
    3 5 6 1
    4 1 4 9
    5 3 4 7
\end{filecontents*}

\begin{document}
    \pgfplotstabletypeset[
        assign column name/.style= {%
            if first column -> /pgfplots/table/column name={#1}
            else -> /pgfplots/table/column name={#1 $\left[\frac{1}{\textrm{s}}\right]$}
        },
    ] {data.csv}
\end{document}

What is the proper way to tackle this problem?

3
  • You could use a counter which you increase globally in each header cell, and check the counter's state to decide whether the changes should apply or not. That's all I'll help as long as you don't post a minimal working example (MWE).
    – Skillmon
    Dec 2, 2017 at 13:52
  • As far as I have seen it shouldn't be necessary to use a custom counter as there is \pgfplotstablecol that already does keep the current column number...
    – Raven
    Dec 2, 2017 at 14:41
  • I don't find a possibility how \pgfplotstablecol should work in this context (the documentation isn't using it like it would be necessary and I can't get it to work...)
    – Skillmon
    Dec 2, 2017 at 15:54

1 Answer 1

1

Using an own counter the solution is rather simple:

\documentclass{article}
\usepackage{pgfplotstable}
\usepackage{filecontents}

\begin{filecontents*}{data.csv}
    a b c d
    1 4 5 1
    2 3 1 5
    3 5 6 1
    4 1 4 9
    5 3 4 7
\end{filecontents*}

\newcount\Ravenfoo

\begin{document}
\pgfplotstabletypeset[
  assign column name/.style = {%
    /pgfplots/table/column name = {
      \ifnum\Ravenfoo>0%
          #1 $\left[\frac{1}{\textrm{s}}\right]$
      \else
        \global\advance\Ravenfoo by 1\relax
        #1
      \fi%
    }
  },
] {data.csv}
\end{document}
2
  • Works like charm. Thanks for your effort! Do you think there is an advantage in using a bool rather than a counter?
    – Raven
    Dec 2, 2017 at 17:25
  • 1
    It is a counter, but since it is only needed to detect the first column, there is no reason to increase it further. You might change the \ifnum\Ravenfoo>0 to >3 and it'll still work out. Remember to set the counter back to 0 if you use it more than once (Ravenfoo=1\relax). I don't think using a pure Boolean variable gives any advances here, though, for versatility. You could as well use one for only this use case though.
    – Skillmon
    Dec 2, 2017 at 17:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .