5

I'm trying to change the background color of the cells FOO and BAR and also the ones with the values (1 and 2) in the following MWE:

\documentclass[12pt]{article}
\usepackage[active,pdfpage,tightpage]{preview}
\PreviewEnvironment[{[]}]{center}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{pgfplotstable}
\usepackage{array}
\usepackage{colortbl}
\usepackage{booktabs}
\usepackage{amsmath}
\usepackage{multirow}
\usepackage{siunitx}

\begin{document}
\begin{center}
\pgfplotstabletypeset[multicolumn names,
    every first column/.style={
        column type/.add={|}{},
        assign cell content/.code={%
            \ifnum\pgfplotstablerow=0
                \pgfkeyssetvalue{/pgfplots/table/@cell content}
            {\multirow{2}{*}{BAR}}%
            \else
                \pgfkeyssetvalue{/pgfplots/table/@cell content}{}%
                \fi
        }
    },every last row/.style={after row=\hline},
    every head row/.style={
        before row={\cline{4-6}
            \multicolumn{1}{c}{} &   & & \multicolumn{3}{c|}{FOO}\\
        },
        after row=\hline
    },
    columns/0/.style = {column name =}, columns/1/.style = {column name =,dec sep align={c|}},
    columns/2/.style={
        column name=1,
        string type,
        column type={|S[round-mode=figures,round-precision=2,table-format=2.2,round-mode=places,scientific-notation=fixed]},
        preproc/expr={##1/1e3}
    },
    columns/3/.style={
        column name=2,
        string type,
        column type={S[round-mode=figures,round-precision=2,table-format=2.2,round-mode=places,scientific-notation=fixed]},
        preproc/expr={##1/1e3},dec sep align={c|},column type/.add={}{|}
    }
]{
0   1   3e+3 4e+3
0   2   5e+3 6e+3
}
\end{center}
\end{document}

I've tried to play with \columncolor{lightgray} as done here, but I'm not getting anywhere. Can I achieve this somehow ?

  • did you figure it out? – Wakan Tanka May 14 '16 at 20:07
  • Unfortunately, no. – BigDawg May 16 '16 at 12:23
2

I've only highlighted the FOO and BAR parts since the others are relatively straightforward.

\documentclass[12pt]{article}
\usepackage{colortbl}
\usepackage{multirow}
\usepackage{siunitx}
\usepackage{pgfplotstable}
\pgfplotsset{compat=newest}

\begin{document}
\pgfplotstabletypeset[multicolumn names,
  every first column/.style={
    column type/.add={|}{},
    assign cell content/.code={%
      \ifnum\pgfplotstablerow=1\relax%
        \pgfkeyssetvalue{/pgfplots/table/@cell content}{\cellcolor{gray}\multirow{-2}{*}{BAR}}%
      \else
        \pgfkeyssetvalue{/pgfplots/table/@cell content}{\cellcolor{gray}}%
      \fi
    }
  },every last row/.style={after row=\hline},
  every head row/.style={
    before row={\cline{4-6}
        \multicolumn{1}{c}{} &   & & \multicolumn{3}{c|}{\cellcolor{gray}FOO}\\
    },
    after row=\hline
  },
  columns/0/.style = {column name =},
  columns/1/.style = {column name =,dec sep align={c|}},
  columns/2/.style={
    column name=1,
    string type,
    column type={|S[round-mode=figures,round-precision=2,table-format=2.2,round-mode=places,scientific-notation=fixed]},
    preproc/expr={##1/1e3}
  },
  columns/3/.style={
    column name=2,
    string type,
    column type={S[round-mode=figures,round-precision=2,table-format=2.2,round-mode=places,scientific-notation=fixed]},
    preproc/expr={##1/1e3},dec sep align={c|},column type/.add={}{|}
  }
]{
0   1   3e+3 4e+3
0   2   5e+3 6e+3
}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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