3

I'm following the solution presented here. However, for some reason when I used the code as a style defined in pgfplotstableset the header disappears. How can I fix it?

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{measurements.dat}
rs ws errorXT errorYT errorG
   5       80      19.125        200        210.02
  15      520      410.00     430        350
  25      650      640.24654        630.2      900
  35     1100     1200.388        1150       1020
\end{filecontents}
\usepackage{pgfplots, pgfplotstable, booktabs, colortbl, siunitx, array}

\pgfplotstableset{
  stripes/.style={
    columns/errorG/.style={
      column name=Error,
      precision=1
    },
    every even row/.style={
      before row={\rowcolor{#1}}
    },
    every head row/.style={
      before row=\hline\noalign{\smallskip},after row=\hline
    },
    every last row/.style={
      after row=\hline
    }
  },
  stripes/.default={gray!50},
  mytable/.style={
    assign column name/.code=\pgfkeyssetvalue{/pgfplots/table/column name}{{{#1}}},
    columns={rs, ws, errorXT, errorYT, errorG},
    columns/rs/.style={
     assign column name={$RS$}, 
      column type={S[]}, string type,
    },
    columns/ws/.style={%
      assign column name={$WS$},
      column type={S[]}, string type,
    }, 
    columns/errorXT/.style={%
      assign column name={Error $XT$},
      column type={S[table-format=4.1]}, string type,
    },
    columns/errorYT/.style={%
      assign column name={Error $YT$},
      column type={S[table-format=4.1]}, string type,
    },
    columns/errorG/.style={%
      assign column name={Error},
      column type={S[table-format=4.1]}, string type,
    },
    stripes
  }
}
\sisetup{table-auto-round}

\pagestyle{empty}
\begin{document}
% doesn't show headers
\pgfplotstabletypeset[mytable]{measurements.dat}
% shows the headers
\pgfplotstabletypeset[
  assign column name/.code=\pgfkeyssetvalue{/pgfplots/table/column name}{{{#1}}},
  columns={rs, ws, errorXT, errorYT, errorG},
  columns/rs/.style={
   assign column name={$RS$}, 
    column type={S[]}, string type,
  },
  columns/ws/.style={%
    assign column name={$WS$},
    column type={S[]}, string type,
  }, 
  columns/errorXT/.style={%
    assign column name={Error $XT$},
    column type={S[table-format=4.1]}, string type,
  },
  columns/errorYT/.style={%
    assign column name={Error $YT$},
    column type={S[table-format=4.1]}, string type,
  },
  columns/errorG/.style={%
    assign column name={Error},
    column type={S[table-format=4.1]}, string type,
  },
  stripes
]{measurements.dat}
\end{document}

The image on the left is the one using the style, and in the right I just copy pasted the same code into the table.

enter image description here

1 Answer 1

3

The keys are expanded various number of times depending on the context they are evaluated. Here, it needs ##1 instead of #1 on the line

assign column name/.code=\pgfkeyssetvalue{/pgfplots/table/column name}{{{##1}}},

inside the mytable style. Then the result is identical.

You must log in to answer this question.

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