isn't the whole problem an instance of http://www.tex.ac.uk/cgi-bin/texfaq2html?label=topgraph quite how you'd integrate the solution into a table, i'm not sure, but surely that's the sort of direction to attack?