I recently stumbled over pgfplotstable and its ability to process table information and create new columns. To hone my skills, I tried to create a script that would calculate an exponential smoothing forecast for a timeseries for different smoothing factors.

The calculation and plotting seems to have worked just fine, but I could not manage to give each of the new columns in the table a new column name that would appear if I print out the table using \pgfplotstabletypeset.

The assignment in general seems to work (i.e. the column name is changed from its default, however, all columns end up having the same column name, when I print the table. Attached is my stripped down case:

    \pgfplotsset{compat=newest,width=10cm,legend style={font=\footnotesize}}

    % read observed time-series
    x   y
    1   4.237485502
    2   5.593257216
    3   6.101509413
    4   5.328536597
    5   6.353556834
    6   5.84178478
    7   5.271878886
    8   6.952802431
    9   4.579257831
    10  7.742456136

    % get first x-Value as forecast value for period 1
    % iterate through different levels of \alpha
    \pgfplotsforeachungrouped \alph in {10,20,...,50}{
            expr accum={ % in the first row, do not calculate forecast as linear combination of actual demand and forecast of last period, but just use initial value
        % set name for column and display style
        \pgfplotstableset{columns/\expandafter\alph/.style={column name={$ES_{\alph}$},dec sep align={c}}}
    % print forecasted values
                    header=has colnames
        \caption{Results of the Exponential Smoothing Excercise (Table)}

    % plot observed and forecasted timeseries
                    legend cell align=left,legend pos=north west,
                \addplot[only marks] table[y=y,x=x]{\mytable};
                \addlegendentry{Original Data};
                \pgfplotsinvokeforeach {10,20,...,50}{
                    \addplot +[mark=none,thin] table[y=#1,x=x]{\mytable};
        \caption{Results of the Exponential Smoothing Excercise (Plot)}


While you're at it: Do you know how I can define the values for alpha (10,20,...,50 in my code) only once and reuse it? I am aware that this is a different question, but my first attempts did not work and these might be low hanging fruits for you ;-)

  • 1
    You need expanded style hence estyle \pgfplotstableset{columns/\alph/.estyle={column name={$ES_{\alph}$},dec sep align={c}}}. Also that \expandafter does not do anything. If you want to expand that one too, you need to start from \pgfplotstableset and the first brace.
    – percusse
    Commented Oct 19, 2014 at 18:55
  • Great, that worked! The \expandafter was a remainder of my attempts to fix the problem because I assumed it would come down to expansion, but I was not aware of the .estyle property.
    – Henning
    Commented Oct 19, 2014 at 20:09

1 Answer 1


To close the threat here: The solution suggested by percusse works perfectly!

Here is the essential part of the line of code that assigns the column name within \pgfplotsforeachungrouped:

\pgfplotstableset{columns/\alph/.estyle={column name={$ES_{\alph}$}}}

You must log in to answer this question.

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