3

Let's look at this MWE, where I am trying to change the formatting/background of a cell in the table. I think I have just copied the example in the manual, but I have the nasty effect that the content of the cell is "disturbed":

enter image description here

what am I doing wrong?

% vim: set spelllang=en :
\documentclass{article}

%
\usepackage{siunitx}
\DeclareSIUnit{\krypt}{\ensuremath{\mathcal{K}r}}
\usepackage{tikz}
\usepackage{pgfplots}\pgfplotsset{compat=1.9} 
\usepackage{pgfplotstable}
\usepackage{booktabs, colortbl}

\pgfplotstableread{
    kr  Rreal   Rlin    deltaR
    0   138.16  143     -4.84
    1   154.18  159.8   -5.62
    2   195.01  176.6   18.41
    3   202.82  193.4   9.42
    4   205.55  210.2   -4.65
}{\fitR}

\begin{document}

With the "single cell" changes: 

    \pgfplotstabletypeset[zerofill, dec sep align,
        %begin table={\begin{tabular}[b]},
        columns/kr/.style={precision=1, column name={Kryptorad (\si{\krypt})}},
        columns/Rreal/.style={precision=2, column name={$R(c)$ (real) (\si{k\ohm})}},
        columns/Rlin/.style={precision=2, column name={$R(c)$ (lin) (\si{k\ohm})}},
        columns/deltaR/.style={precision=2, column name={$\epsilon_\mathrm{abs}$ (lin) (\si{k\ohm})}},
        every head row/.style={before row=\toprule,after row=\midrule},
        every last row/.style={after row=\bottomrule},
        every row 2 column 3/.style={
            % stupid example for multiple postprocessors:
            postproc cell content/.append style={
                /pgfplots/table/@cell content/.add={\cellcolor{red!10!white}}{},
            }
        },
        every row 3 column 3/.style={postproc cell content/.style=
            {@cell content=\textbf{##1}}}
    ]{\fitR}

    Without: 

    \pgfplotstabletypeset[zerofill, dec sep align,
        %begin table={\begin{tabular}[b]},
        columns/kr/.style={precision=1, column name={Kryptorad (\si{\krypt})}},
        columns/Rreal/.style={precision=2, column name={$R(c)$ (real) (\si{k\ohm})}},
        columns/Rlin/.style={precision=2, column name={$R(c)$ (lin) (\si{k\ohm})}},
        columns/deltaR/.style={precision=2, column name={$\epsilon_\mathrm{abs}$ (lin) (\si{k\ohm})}},
        every head row/.style={before row=\toprule,after row=\midrule},
        every last row/.style={after row=\bottomrule},
    ]{\fitR}

\end{document}
  • 1
    you are overwriting the cell content for two columns (dec sep align is active). – percusse Feb 29 '16 at 19:34
  • 1
    @percusse Aaaaargh... ok, gotcha. Now --- is it solvable maintaining the nice alignment? Thanks! – Rmano Feb 29 '16 at 19:39
  • It is but pretty tedious as far as I remember. Also Christian is not hopeful either here tex.stackexchange.com/questions/276395/… – percusse Feb 29 '16 at 20:19
1

Given the instrinsic problem of mixing the dec sep align option with single-cell property, I found this solution/workaround:

  • switching the dec sep align off,
  • changing the column to r type,
  • using fixed

Code:

 \pgfplotstabletypeset[zerofill, 
    %dec sep align,
    columns/kr/.style={precision=1, column name={Kryptorad (\si{\krypt})}},
    columns/Rreal/.style={precision=2, column name={$R(c)$ (real) (\si{k\ohm})}},
    columns/Rlin/.style={precision=2, column name={$R(c)$ (lin) (\si{k\ohm})}},
    columns/deltaR/.style={precision=2, column name={$\epsilon_\mathrm{abs}$ (lin) (\si{k\ohm})},
        column type={r}, fixed},
    every head row/.style={before row=\toprule,after row=\midrule},
    every last row/.style={after row=\bottomrule},
    every row 2 column 3/.style={
        % stupid example for multiple postprocessors:
        postproc cell content/.append style={
            /pgfplots/table/@cell content/.add={\cellcolor{red!10!white}}{},
        }
    },
    every row 3 column 3/.style={postproc cell content/.style=
        {@cell content=\textbf{##1}}}
]{\fitR}

Resulting in:

Resulting table

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.