在这个示例表中,如何画一条从 (1,2) 到 (4,2) 的线?
\documentclass{standalone}
\usepackage{filecontents}
\begin{filecontents}{data.dat}
C1 C2
6 80
15 520
25 650
35 1100
\end{filecontents}
\usepackage{pgfplots, pgfplotstable, booktabs, colortbl}
\pgfplotsset{compat=1.8}
\pgfplotstableset{
every head row/.style={before row={\toprule},after row={\midrule}},
every last row/.style={after row={\bottomrule}},
every even row/.style={before row={\rowcolor[gray]{0.9}}},
columns/.style={dec sep align,%column type=c
}
}
\begin{document}
\pgfplotstabletypeset[]{data.dat}
\end{document}
答案1
先验pgfplotstable
不会将其单元放入节点中。因此我们必须自己做这件事。这可以使用assign cell content/.code
和tikzmark
库来完成。请注意埃之前value
(\pgfkgyssetevalue
以及\noexpand
)需要“技巧”来pgfplotstable
与我们共享行和列索引以创建唯一的节点名称。
\documentclass{standalone}
\begin{filecontents}[overwrite]{data.dat}
C1 C2
6 80
15 520
25 650
35 1100
\end{filecontents}
\usepackage{pgfplots,pgfplotstable, booktabs, colortbl}
\usetikzlibrary{tikzmark}
\pgfplotsset{compat=1.17}
\pgfplotstableset{
every head row/.style={before row={\toprule},after row={\midrule}},
every last row/.style={after row={\bottomrule}},
every even row/.style={before row={\rowcolor[gray]{0.9}}},
columns/.style={dec sep align,%column type=c
},assign cell content/.code={%
\pgfkeyssetevalue{/pgfplots/table/@cell content}{%
\noexpand\tikzmarknode{mytab-\the\numexpr\pgfplotstablerow+1\relax-\the\numexpr\pgfplotstablecol+1\relax}{#1}}}
}
\begin{document}
\pgfplotstabletypeset[]{data.dat}
\begin{tikzpicture}[overlay,remember picture]
\draw[blue] (mytab-1-2) to[bend right=50] (mytab-4-2);
\end{tikzpicture}
\end{document}