Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm trying to change the cell color and text color of the header of a pgfplotstable. Changing the cell color is not that much of a problem because I can just prefix the row with \rowcolor:

\documentclass{standalone}
\usepackage{colortbl}
\usepackage{pgfplotstable}
\definecolor{cellshade}{rgb}{0.42, 0.55, 0.84}
\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}
\begin{document}
\pgfplotstabletypeset[
    col sep=comma,
    column type={C{5em}},
every first column/.style={reset styles,string type,column type={>{\color{white}\cellcolor{cellshade}\arraybackslash}C{5em}}},
%    /pgfplots/colormap={orangewhiteorange}{color=(myorange) color=(white) color=(myorange)},
%    color cells={min=-1,max=1,textcolor=black},
    every head row/.style={before row={\rowcolor{cellshade}}},
    /pgf/number format/fixed,
    /pgf/number format/skip 0.
]{
Component,1,2,3
1,1.000,.186,.074
2,.186,1.000,.003
3,.074,.003,1.000
}
\end{document}

table with black header text

But clearly what the table should look like is this:

table with white header text

I'm stuck finding a good way to change the header text color though. I could change the name of each individual column but that's pretty inelegant. I know that I could in principle adapt this answer but it's not only also very inelegant IMHO (it changes the font style of the whole table first and then reverses this in postprocessing), it's also a solution that doesn't scale in general and in my case in particular it's not really applicable because a detail that I've mostly left out of the above MWE is that I postprocess the table cells anyway. I use this code to color in the table body, so this is what the table actually looks like (or should look like at least):

table with right header and colored cells

Sure, I could adapt this code but I'm using it in other tables, too, and going this route would lead to disaster sooner or later. It's also not The Right Thing To Do™.

So, long story short, how do I add font commands (or, I imagine, any other commands) to header cells in particular, without affecting the rest of the table.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Apparently I still don't remember the relevant code in How to rotate head row cell entries of pgfplotstable :)

I believe this can be a feature request.

\documentclass[border=5mm]{standalone}
\usepackage{colortbl}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.10}
\definecolor{cellshade}{rgb}{0.42, 0.55, 0.84}
\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}
\begin{document}
\pgfplotstabletypeset[
    col sep=comma,
    column type={C{5em}},
    every first column/.style={reset styles,string type,
                        column type={>{\color{white}\cellcolor{cellshade}\arraybackslash}C{5em}}
                        },
    every head row/.append style={
        before row={\rowcolor{cellshade}},
        typeset cell/.code={
        \ifnum\pgfplotstablecol=\pgfplotstablecols
        \pgfkeyssetvalue{/pgfplots/table/@cell content}{\textcolor{white}{##1}\\}%
        \else
        \pgfkeyssetvalue{/pgfplots/table/@cell content}{\textcolor{white}{##1}&}%
        \fi
        }
    },
    /pgf/number format/fixed,
    /pgf/number format/skip 0.
]{
Component,1,2,3
1,1.000,.186,.074
2,.186,1.000,.003
3,.074,.003,1.000
 }
\end{document}

enter image description here

share|improve this answer
    
Works great, even with the added code to color in the table cells! But yeah, it would be nice if there was an easier way to do this. I can imagine that setting a certain font style specifically for the header is quite a common use case in one way or another. –  Christian Apr 2 at 14:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.