8

Is it possible with pgfplotstable to check if a cell is not empty and put a \midrule before this row?

For example I have the names of a sample in the first column and before every new sample I want a \midrule. If every sample has the same amount of rows I could use the every nth row option of pgfplotstable.

But how can I solve this, if the amount of rows per sample is not the same? Here a MWE which illustrates the problem:

\documentclass{article}    
\usepackage{pgfplotstable, booktabs}

\begin{filecontents}{dataC.csv}
Name,    pH,     concentration
Sample 1,   1.01,      1.52
    ,   1.00,   1.51
    ,   1.02,   1.53
Sample 2,   2.01,      -1.52
    ,   2.00,   -1.51
    ,   2.02,   -1.53
Sample 3,   3.01,      -2.52
    ,   3.00,   -2.51
Sample 4,   4.01,      -3.52
    ,   4.00,   -3.51
    ,   4.02,   -4.53
    ,   4.01,   -3.51
    ,   4.03,   -3.54
Sample 5,   5.01,      -4.52
    ,   5.00,   -4.51
    ,   5.02,   -4.53
\end{filecontents}    

\begin{document}

\pgfplotstableset{col sep=comma}
\pgfplotstabletypeset[
    columns={Name, pH, concentration}, 
    fixed zerofill, 
    columns/Name/.style={string type,},
    every head row/.style={before row=\toprule, after row=\midrule},
    every last row/.style={after row=\bottomrule},
    every nth row={3}{before row=\midrule},
    ]{dataC.csv}

\end{document}

1 Answer 1

2

You can use every row no <index>. It affords manual counting of the rows and adding the style for each affected row again, but…

\documentclass{article}
\usepackage{pgfplotstable, booktabs}

\begin{filecontents}{dataC.csv}
Name,    pH,     concentration
Sample 1,   1.01,      1.52
    ,   1.00,   1.51
    ,   1.02,   1.53
Sample 2,   2.01,      -1.52
    ,   2.00,   -1.51
    ,   2.02,   -1.53
Sample 3,   3.01,      -2.52
    ,   3.00,   -2.51
Sample 4,   4.01,      -3.52
    ,   4.00,   -3.51
    ,   4.02,   -4.53
    ,   4.01,   -3.51
    ,   4.03,   -3.54
Sample 5,   5.01,      -4.52
    ,   5.00,   -4.51
    ,   5.02,   -4.53
\end{filecontents}

\begin{document}

\pgfplotstableset{col sep=comma}
\pgfplotstabletypeset[
    columns={Name, pH, concentration}, 
    fixed zerofill, 
    columns/Name/.style={string type,},
    every head row/.style={before row=\toprule, after row=\midrule},
    every last row/.style={after row=\bottomrule},
    every row no 3/.style={before row=\midrule},
    every row no 6/.style={before row=\midrule},
    every row no 8/.style={before row=\midrule},
    every row no 13/.style={before row=\midrule},
    ]{dataC.csv}

\end{document}

enter image description here

1
  • this solution is a possibility. But I thought there should be a solution with less manual action. Main problem here if I have to change the amount of rows of only one sample, I have to adjust all following every row no. I could accept this answer if it would be possible to use a counter as row number and increase it manually by \addtocounter but this is not possible in the optional argument of pgfplotstypeset. Do you have an idea how to solve this? At least for an idea I would be really thankful.
    – Schewerle
    Jan 23, 2017 at 15:01

You must log in to answer this question.

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