在 pgfplotstable 中的特定单元格之间放置一个行分隔符

在 pgfplotstable 中的特定单元格之间放置一个行分隔符

我有pgfplotstable一个 CSV 数据源。这是我当前的代码:

\documentclass[12pt]{report}

\usepackage{pgfplotstable}

\begin{document}
    \begin{table}
        \centering
        \pgfplotstabletypeset[
        col sep=comma,
        columns={V1,I1,V2,I2,V3,I3,V4,I4},
        columns/V1/.style={column name=$V_a$ (V)},
        columns/V2/.style={column name=$V_a$ (V)},
        columns/V3/.style={column name=$V_a$ (V)},
        columns/V4/.style={column name=$V_a$ (V)},
        columns/I1/.style={column name=$I$ (nA), column type={l|}},
        columns/I2/.style={column name=$I$ (nA), column type={l|}},
        columns/I3/.style={column name=$I$ (nA), column type={l|}},
        columns/I4/.style={column name=$I$ (nA)},
        fixed,
        fixed zerofill,
        display columns/0/.style={precision=1},
        display columns/2/.style={precision=1},
        display columns/4/.style={precision=1},
        display columns/6/.style={precision=1},
        display columns/1/.style={precision=3},
        display columns/3/.style={precision=3},
        display columns/5/.style={precision=3},
        display columns/7/.style={precision=3},
        every head row/.style={after row=\hline}]
        {data.csv}
        \caption{A table}
    \end{table}
\end{document}

\begin{filecontents}{data.csv}
    V1,I1,V2,I2,V3,I3,V4,I4
    39.2,0.897,29.8,0.416,19.4,0.150,8.7,0.010
    38.8,0.909,29.4,0.356,18.5,0.173,8.3,0.007
    38.5,0.947,29.0,0.332,18.1,0.198,7.9,0.005
    37.9,1.035,28.7,0.350,17.5,0.230,7.6,0.004
    37.4,1.128,28.3,0.389,16.6,0.212,7.1,0.002
    37.1,1.142,28.0,0.433,16.2,0.181,6.7,0.001
    36.5,1.130,27.5,0.542,15.7,0.135,6.3,0.001
    36.1,1.037,26.7,0.628,15.3,0.110,5.7,0.000
    35.7,0.902,25.9,0.510,15.0,0.093,5.3,0.000
    35.4,0.779,25.5,0.407,14.5,0.085,4.8,0.000
    35.0,0.673,25.1,0.320,14.2,0.082,4.3,0.000
    34.7,0.601,24.7,0.264,13.7,0.086,3.7,0.000
    34.1,0.542,24.3,0.230,13.3,0.088,3.4,0.000
    33.8,0.547,24.0,0.224,13.0,0.086,3.0,0.000
    33.4,0.590,23.6,0.241,12.6,0.083,2.6,0.000
    33.1,0.624,22.9,0.322,11.8,0.063,2.2,0.000
    32.6,0.760,22.6,0.364,11.5,0.050,1.9,0.000
    32.2,0.835,22.0,0.422,11.0,0.037,1.5,0.000
    31.8,0.872,21.6,0.410,10.6,0.027,1.1,0.000
    31.4,0.845,21.3,0.379,10.2,0.021,0.7,0.000
    31.0,0.758,20.7,0.276,9.8,0.017,0.0,0.000
    30.6,0.638,20.4,0.234,9.4,0.014,,
    30.3,0.541,19.8,0.167,9.1,0.011,,
\end{filecontents}

我正在寻找一种在两个特定单元格之间划线的方法,如下所示: 带线的表格

我尝试了一些附加代码来检查的方法\pgfplotstablerow,但我不知道如何添加该行。我pgfplotstable以前从未使用过该包,所以我不知道从哪里开始。

答案1

例如

every row no 15/.style={
    after row={\cline{3-4}}
}

将添加\cline{3-4}到第 16 个数据行之后(因为第 16 个数据pgfplotstable行具有从零开始的索引)。

every row no N是用于行号 N 的样式,after row用于\\在行后添加内容。

\documentclass[12pt]{report}

\usepackage{pgfplotstable,filecontents}
\begin{filecontents}{data.csv}
    V1,I1,V2,I2,V3,I3,V4,I4
    39.2,0.897,29.8,0.416,19.4,0.150,8.7,0.010
    38.8,0.909,29.4,0.356,18.5,0.173,8.3,0.007
    38.5,0.947,29.0,0.332,18.1,0.198,7.9,0.005
    37.9,1.035,28.7,0.350,17.5,0.230,7.6,0.004
    37.4,1.128,28.3,0.389,16.6,0.212,7.1,0.002
    37.1,1.142,28.0,0.433,16.2,0.181,6.7,0.001
    36.5,1.130,27.5,0.542,15.7,0.135,6.3,0.001
    36.1,1.037,26.7,0.628,15.3,0.110,5.7,0.000
    35.7,0.902,25.9,0.510,15.0,0.093,5.3,0.000
    35.4,0.779,25.5,0.407,14.5,0.085,4.8,0.000
    35.0,0.673,25.1,0.320,14.2,0.082,4.3,0.000
    34.7,0.601,24.7,0.264,13.7,0.086,3.7,0.000
    34.1,0.542,24.3,0.230,13.3,0.088,3.4,0.000
    33.8,0.547,24.0,0.224,13.0,0.086,3.0,0.000
    33.4,0.590,23.6,0.241,12.6,0.083,2.6,0.000
    33.1,0.624,22.9,0.322,11.8,0.063,2.2,0.000
    32.6,0.760,22.6,0.364,11.5,0.050,1.9,0.000
    32.2,0.835,22.0,0.422,11.0,0.037,1.5,0.000
    31.8,0.872,21.6,0.410,10.6,0.027,1.1,0.000
    31.4,0.845,21.3,0.379,10.2,0.021,0.7,0.000
    31.0,0.758,20.7,0.276,9.8,0.017,0.0,0.000
    30.6,0.638,20.4,0.234,9.4,0.014,,
    30.3,0.541,19.8,0.167,9.1,0.011,,
\end{filecontents}
\begin{document}
        \pgfplotstabletypeset[
        col sep=comma,
        columns={V1,I1,V2,I2,V3,I3,V4,I4},
        columns/V1/.style={column name=$V_a$ (V)},
        columns/V2/.style={column name=$V_a$ (V)},
        columns/V3/.style={column name=$V_a$ (V)},
        columns/V4/.style={column name=$V_a$ (V)},
        columns/I1/.style={column name=$I$ (nA), column type={l|}},
        columns/I2/.style={column name=$I$ (nA), column type={l|}},
        columns/I3/.style={column name=$I$ (nA), column type={l|}},
        columns/I4/.style={column name=$I$ (nA)},
        fixed,
        fixed zerofill,
        display columns/0/.style={precision=1},
        display columns/2/.style={precision=1},
        display columns/4/.style={precision=1},
        display columns/6/.style={precision=1},
        display columns/1/.style={precision=3},
        display columns/3/.style={precision=3},
        display columns/5/.style={precision=3},
        display columns/7/.style={precision=3},
        every head row/.style={after row=\hline},
        every row no 14/.style={after row={\cline{3-4}}}
        ]
        {data.csv}
\end{document}

在此处输入图片描述

答案2

鉴于您没有提供完整的示例,我将提供一个与我的“操作方法”片段中所做的类似的片段。

这个想法是将几个添加tikzmark到感兴趣的单元格中,然后使用tikzpicture覆盖我们想要的任何内容。它实际上无法扩展到很多添加的行,但是……这个例子使用的是booktabs,所以你必须根据你的情况进行调整。

这里的优点是标记不会以任何方式改变表格,因此您拥有完全相同的间距。

\documentclass[border=10pt]{standalone}
\usepackage{siunitx}
\usepackage[table]{xcolor}
\usepackage{pgfplots}\pgfplotsset{compat=1.9}
\usepackage{pgfplotstable}
\usepackage{booktabs}
\usetikzlibrary{tikzmark}

\pgfplotstableread{
    kr  Rreal   Rlin    voideal vocal
    0   138.16  143     0       -0.32
    1   154.18  159.8   1       0.65
    2   195.01  176.6   2       3.11
    3   202.82  193.4   3       3.58
    4   205.55  210.2   4       3.74
}{\fullA}
\begin{document}

    \pgfplotstabletypeset[zerofill, fixed,
        column type={r},
        %multicolumn names={c},
        %dec sep align,
        %begin table={\begin{tabular}[b]},
        columns/kr/.style={precision=1, column name={Kryptorad},
        column type/.add={>{\bfseries\boldmath}}{}},
        columns/Rreal/.style={precision=2, column name={$R(c)$}},
        columns/Rlin/.style={precision=2, column name={$R(c)$}},
        columns/voideal/.style={precision=2, column name={$v_o$}},
        columns/vocal/.style={precision=2, column name={$v_o$}},
        every head row/.style={before row=\toprule},
        every last row/.style={after row=\bottomrule},
        every row no 2/.style={before row={\rowcolor{red!10}}},
        % mark the cells
        every row no 3 column no 2/.style={
            postproc cell content/.style={@cell content/.add={\tikzmark{A}}{}},
        },
        every row no 3 column no 3/.style={
            postproc cell content/.style={@cell content/.add={}{\tikzmark{B}}},
        }
    ]{\fullA}
    \begin{tikzpicture}[overlay, remember picture]
        \draw [red] ([yshift=-2pt]pic cs:A) -- ([yshift=-2pt]pic cs:B);
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容