2
$\begingroup$

I have a simple graph:

mygraph = Graph[{1 -> 2, 2 -> 3, 3 -> 1}]

and a simple table:

mytable = 
 TableForm[{{a, b}, {c, d}, {e, f}}, 
  TableHeadings -> {{"r1", "r2", "r3"}, {"c1", "c2"}}]

and I would like to place the table adjacent one of the vertices in the graph.

I've tried Epilog, and converting mytable into some form of graphic to Show[] them overlapped, without success.

As mentioned:

Graph[{1 -> 2, 2 -> 3, 3 -> 1},
 Epilog -> 
  Graphics@TableForm[{{a, b}, {c, d}, {e, f}}, 
    TableHeadings -> {{"r1", "r2", "r3"}, {"c1", "c2"}}]]

(and obvious variations thereon) fails.

$\endgroup$
  • 1
    $\begingroup$ Can you show your attempt with Epilog? $\endgroup$ – Szabolcs Feb 25 at 17:55
  • $\begingroup$ Perhaps GraphicsGrid could help, since it automatically outputs a Graphics object? Something along the lines of GraphicsGrid[ {{"", "c1", "c2"}, {"r1", a, b}, {"r2", c, d}, {"r3", e, f}}, Dividers -> {{False, True}, {False, True}}] $\endgroup$ – MarcoB Feb 25 at 19:12
  • $\begingroup$ Graphics is not a graphics primitive, and won't convert something to graphics. It can't be used in Epilog. Use either Inset or Text (and set the coordinates too). $\endgroup$ – Szabolcs Feb 25 at 19:40
4
$\begingroup$

You can use Epilog -> Inset[...]:

Graph[mygraph,  ImagePadding -> {{100, 10}, {40, 10}},
 Epilog -> Inset[mytable, PropertyValue[{mygraph, 1}, VertexCoordinates], Right, Scaled[1]]]

enter image description here

Alternatively, you can label a specific vertex using Labeled or VertexLabels -> ...:

Graph[mygraph,  VertexLabels -> {_ :> "Name", 1 -> Placed[mytable, Before]}]

or

Graph[{Labeled[3, mytable, Before], 2, 3}, EdgeList@mygraph, VertexLabels -> "Name"]

enter image description here

$\endgroup$
  • $\begingroup$ Thanks very much. (Accept) $\endgroup$ – David G. Stork Feb 26 at 3:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.