TransWikia.com

annotation on pgfplot table

TeX - LaTeX Asked on March 3, 2021

In this example table, how can I draw a line from (1,2) to (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}

enter image description here

One Answer

A priori pgfplotstable does not put its cells in nodes. So we have to do that on our own. This can be done using assign cell content/.code and the tikzmark library. Please note the e before value in pgfkgyssetevalue (and the noexpand) which was required to "trick" pgfplotstable to share the row and column indices with us to create unique node names.

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}{%
    noexpandtikzmarknode{mytab-thenumexprpgfplotstablerow+1relax-thenumexprpgfplotstablecol+1relax}{#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}

enter image description here

Correct answer by user231225 on March 3, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP