6

I'm using pgfplotstable to create tables from .csv-files. But when I use postproc cell content to change the appearence of a specific cell, all former formatting of this cell seems to be ignored. How can I make changes to the appearence of a specific cell and at the same time preserve a uniform styling of the table?

Here is the MWE:

\documentclass{article}

\usepackage{multirow}
\usepackage{booktabs}
\usepackage{pgfplotstable}

%Make rows higher:
\setlength\extrarowheight{1.4pt}

%GLOBAL FORMATING:
\pgfkeys{/pgf/number format/.cd,
                use comma,
                1000 sep={}}

\usepackage{lipsum}
\usepackage{filecontents}

\begin{filecontents}{data.csv}
Name,1,2
A,10.23,3.23
B,11.23,4.23
C,12.23,5.23
D,13.23,6.23
E,14.23,7.23
F,15.23,8.23
\end{filecontents}

\begin{document}

\lipsum[1]

\begin{table}[!htb]
\centering
\caption{Some text describing the table}

\pgfplotstabletypeset[col sep=comma,
    columns={Name, 1, 2},% <---these columns will appear in the table
%------------------TYPESETTING COLUMNS:-------------------------------
     columns/Name/.style={% <---style column "Name"
      string type,%
      column type/.add={}{|},%
    },
    %
    columns/1/.style={% <---style column "1"
      column name=I,
      precision=1,column type/.add={}{|},%
    },
    %
    columns/2/.style={% <---style column "2"
      column name=II,
      precision=1, column type/.add={}{},%
      postproc cell content/.code={% <--- style row 2 (=index 1) of column "2"
        \ifnum\pgfplotstablerow=1 
            \pgfkeysalso{@cell content=\textcolor{red!100}{##1}}% <---make it red
        \fi
      },
    },
    %
%------------------TYPESETTING ROWS-------------------------------
    every head row/.style={before row=\toprule, after row=\midrule},%
    every last row/.style={after row=\bottomrule}%
    ]%
{data.csv}
\end{table}

\lipsum[2]



\end{document}

And this is, what it looks like:

Obviously the formatting of the red cell differs from the others.

I would like to have the cell containing 4.23 to contain 4,2, so that it is formatted as all the other cells.

Thank you very much in advance!

1
  • 1
    ##1 is a shortcut to the value @preprocessed cell content. In this context you need @cell content
    – percusse
    Jul 6, 2015 at 10:42

1 Answer 1

5

Here is a possible (but I guess not the best) solution:

  postproc cell content/.append code={% <--- style row 2 (=index 1) of
      \ifnum\pgfplotstablerow=1\relax% 
          \edef\temp{%
              \noexpand\pgfkeyssetvalue{/pgfplots/table/@cell content}%
                  {\noexpand\color{red!100}\pgfkeysvalueof{/pgfplots/table/@cell content}}%
          }\temp%
      \fi%
  }

enter image description here

Update:

Using bold font instead of changing the text color (to highlight the cell) is easier:

  \ifnum\pgfplotstablerow=1\relax% 
      \pgfkeysalso{@cell content/.add={$\bf}{$}}
  \fi%
6
  • Looks pretty OK to me.
    – percusse
    Jul 6, 2015 at 11:33
  • @percusse A lot of low level code just to change the text color?
    – sergej
    Jul 6, 2015 at 11:35
  • Haha that's acceptable criticism I guess. But this is rather a lot of low level code for table automation. Imagine you have 50 rows and you look for the minimum etc. then it will pay off.
    – percusse
    Jul 6, 2015 at 11:37
  • Thank you very much! It works as desired. Could I change the cell to bold text with this approach too? I'm sorry, but I really have no clue of how \edef,\expandafter and \noexpand work. And if I just replace \color{red!100} with something else, it only works for things like \tiny etc.
    – Wamseln
    Jul 6, 2015 at 12:05
  • @Wamseln Add \noexpand\boldmath before \noexpand\color
    – sergej
    Jul 6, 2015 at 12:52

You must log in to answer this question.

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