是否可以检查单元格是否不为空并在该行前面pgfplotstable
放置?\midrule
例如,我在第一列中有一个样本的名称,并且我希望在每个新样本之前都有一个\midrule
。如果每个样本都有相同数量的行,我可以使用every nth row
选项pgfplotstable
。
但是,如果每个样本的行数不一样,我该如何解决这个问题?这里有一个 MWE 来说明这个问题:
\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
您可以使用every row no <index>
。它可以手动计算行数并再次为每个受影响的行添加样式,但是……
\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}