# Combining a style with individual post-processing

I’m working on a paper in which I present numerous big tables, all of which should be formatted in the same way. In every table, some entries should be highlighted, e.g. typeset bold. So I want to define a common style and locally specify which cells to highlight.

I have tried various methods, all of which fail in one way or another:

\documentclass{article}

\usepackage{pgfplotstable}

% common style
\pgfplotstableset{mystyle/.style={
columns/rownb/.style = {
column name = {{\#}},
dec sep align,
fixed
}
}}

% common style
\pgfplotstableset{myotherstyle/.style={
columns/rownb/.style = {
column name = {{\#}},
dec sep align,
fixed
},
otherhighlight/.style = {
postproc cell content/.append code=\pgfkeysalso{@cell content=\emph{##1}}
},
every row 1 column rownb/.append style={otherhighlight},
every row 4 column rownb/.append style={otherhighlight}
}}

\begin{document}

% This is how I would like to do it, i.e. local specification of the
% cells to be highlighted
\pgfplotstabletypeset[mystyle,
highlight/.style = {
postproc cell content/.append code=\pgfkeysalso{@cell content=\textbf{##1}}
},
every row 1 column rownb/.append style={highlight},
every row 4 column rownb/.append style={highlight}]{
rownb xs
1 11
2 22
3 33
4 44
5 55
6 66
}

\pgfplotstabletypeset[myotherstyle]{
rownb xs
1 11
2 22
3 33
4 44
5 55
6 66
}

\end{document}


This yields the two tables:

#       xs
1       11
**22**  22
3       33
4       44
**55**  55
6       66

#       xs
1       11
22
3       33
4       44
55
6       66


Here **55** means bold. In the first table the content of the cells to be highlighted gets duplicated. In the second table the content vanishes.

Edit 1: The first approach works, if the column has string type. I vaguely remember that for each column of numeric type pgfplotstable creates an additional column to align numbers properly. So apparently this causes the post-processing to duplicate cell contents. Still, I would like to work it for my case.

It turns out I remembered correctly. I found Pgfplotstable: how can I add percent signs (and respect dec sep align)?, where a similar problem is described. The following works as desired:

\pgfplotstabletypeset[mystyle,
highlight/.style = {
postproc cell content/.append code={
\ifnum0=\pgfplotstablepartno
\pgfkeysalso{@cell content=\textbf{##1}}%
\fi
}
},
every row 1 column rownb/.append style={highlight},
every row 4 column rownb/.append style={highlight}]{
rownb xs
1 11
2 22
3 33
4 44
5 55
6 66
}


Since I don’t want to copy and paste the highlight style into every table, I can factor it out and get:

\documentclass{article}

\usepackage{pgfplotstable}

% commonly used to style tables
\pgfplotstableset{mystyle/.style={
columns/rownb/.style = {
column name = {{\#}}
}
}}

% commonly used to highlight cells
\pgfplotstableset{highlight/.append style={
postproc cell content/.append code={
\ifnum0=\pgfplotstablepartno
\pgfkeysalso{@cell content=\textbf{##1}}%
\fi
}
}}

\begin{document}

\pgfplotstabletypeset[mystyle,
every row 1 column rownb/.append style={highlight},
every row 4 column rownb/.append style={highlight}]{
rownb xs
1 11
2 22
3 33
4 44
5 55
6 66
}

\end{document}

• Nice! Thanks for researching and posting the answer, that's definitely going to come in handy for others. – Jake Jul 3 '13 at 0:22