4

I use pgfplotstable and want to post-format a specific column. Among other things I need to duplicate its content. My problem is that postproc cell content works fine as a direct parameter to pgfplotstabletypeset but not when I try to put it into a style so I can use it for multiple tables.

\documentclass[11pt]{article}
\usepackage{pgfplotstable}

\begin{document}
\begin{table}
\centering

\pgfplotstableread{
A   B   C
1   3.5 2.4
2   1.2 6.7
3   2.1 3.3
}\data

\pgfplotstableset{
 debug,
 mytable/.style={
  columns={A,B,C},
  columns/A/.style={string type,
                    postproc cell content/.style={
                     @cell content=\ensuremath{##1 \leftrightarrow ##1}
                    }
                   },
 }
}

\pgfplotstabletypeset[
    mytable,
%    columns/A/.style={string type,
%                      postproc cell content/.style={
%                       @cell content=\ensuremath{##1 \leftrightarrow ##1}
%                      }
%                     }
]{\data}

\caption{Some important table}
\end{table}

\end{document}

When I enable the commented lines it looks like it should, without them the original numbers are missing.

Sorry, cannot post images...

1 Answer 1

6

This is a little hard to explain ( you can even call it a bug) but each time an argument passes through a style an expansion of # is lost. So you need four # chars.

\documentclass[11pt]{article}
\usepackage{pgfplotstable}

\begin{document}
\begin{table}
\centering

\pgfplotstableread{
A   B   C
1   3.5 2.4
2   1.2 6.7
3   2.1 3.3
}\data

\pgfplotstableset{
 debug,
 mytable/.style={
  columns={A,B,C},
  columns/A/.style={string type,
                    postproc cell content/.style={
                     @cell content=\ensuremath{####1 \leftrightarrow ####1}
                    }
                   },
 }
}

\pgfplotstabletypeset[
    mytable,
%    columns/A/.style={string type,
%                      postproc cell content/.style={
%                       @cell content=\ensuremath{##1 \leftrightarrow ##1}
%                      }
%                     }
]{\data}

\caption{Some important table}
\end{table}

\end{document}

enter image description here

4
  • Thanks a lot! What's really ironic is that I actually tried with three # but got an error and thought this was the wrong approach.
    – TableKing
    Commented May 6, 2013 at 19:30
  • @TableKing It doubles every time. So you need eight of them if you pass it through another /.style
    – percusse
    Commented May 6, 2013 at 19:39
  • I just did add another /.style and still the four # keep working fine...
    – TableKing
    Commented May 6, 2013 at 21:18
  • @TableKing My mistake. It's not just a style but it should be an expansion. I've taken it for granted that a style always expands but that's not the case.
    – percusse
    Commented May 7, 2013 at 17:35

You must log in to answer this question.

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