# Vertex Multi-labeling on a Graph Network

We can have this Graph:

v = {1 \[UndirectedEdge] 9, 1 \[UndirectedEdge] 10,
1 \[UndirectedEdge] 8, 10 \[UndirectedEdge] 2,
10 \[UndirectedEdge] 5, 9 \[UndirectedEdge] 3,
9 \[UndirectedEdge] 6, 8 \[UndirectedEdge] 7,
8 \[UndirectedEdge] 4, 7 \[UndirectedEdge] 3,
7 \[UndirectedEdge] 2, 6 \[UndirectedEdge] 2,
6 \[UndirectedEdge] 4, 5 \[UndirectedEdge] 3,
5 \[UndirectedEdge] 4};
g = Graph[v, VertexLabels -> Placed["Name", Center],
VertexStyle -> White, VertexSize -> 0.5]


Which looks like this: How can I add other characteristics inside the vertex labels?Such as other numbers in second line of labels?Or more info such as some codes in third line?

• I would suggest to change the title: the title talks about VertexStyle while the question deals with VertexLabel. Or am I wrong – Öskå Oct 2 '13 at 16:52
• @Öskå Both could be.Thanks for the offer but still I prefer to stand on my first title – Alex Oct 2 '13 at 17:06
• This is really a question about vertices with multi-labels and it is a very common thing in network graphs. @Pinguin Dirk I would like to see a few more answers, if possible, with GraphPlot and VertexRenderingFunction. Thank you – Athanassios Mar 5 '16 at 21:42

I am sure there must be an easier way (I cannot see at the moment), but it is possible to use VertexLabels the way you want:

labs = CharacterRange["a", "j"];
g = Graph[v,
VertexLabels -> (With[{vtx = Range@VertexCount@Graph@v},
Rule @@@ Transpose[{vtx, Placed[ToString@# <> "\n" <> labs[[#]] "\nsome text",
Center] & /@ vtx}]]),
VertexStyle -> White,
VertexSize -> 0.75]


So, I just count the vertices (vtx) and set up a Rule to format the labels. Note that I used labs as to show how we can use labels that change from vertex to vertex. I hope this is what you had in mind: Also, you might want to look into GraphPlot, and into VertexRenderingFunction in particular.

You could use Labeled. Because 2 of the 3 elements are placed outside the vertex, you can use smaller vertices.

Graph[{ Labeled[1, Placed[{1, "New York", "USA"}, {Center, Above, Below}]],
Labeled[2, Placed[{2, "Paris", "France"}, {Center, Above, Below}]],
Labeled[3, Placed[{3, "Rome", "Italy"}, {Center, Above, Below}]]},
{1 -> 2, 2 -> 3, 3 -> 1},
VertexLabelStyle -> 14, VertexStyle -> White, VertexSize -> 0.1, ImagePadding -> 30] • Are you on Mathematica 9? – Öskå Oct 2 '13 at 17:27
• Yes. I'm on Mathemaica 9. But Labeled does not required 9. – DavidC Oct 2 '13 at 17:29
• I know. But I was wondering why your Graph started on the bottom left while mine started on the right :) So I guess it's some versions differences. – Öskå Oct 2 '13 at 17:31
• On my machine, your code places the vertices in the same positions as my code. So, if you are using v 9, I can't explain the discrepancy. – DavidC Oct 2 '13 at 17:33
• And on mine, your code places the vertices on the same positions as mine ;-) Hence the version question. – Öskå Oct 2 '13 at 17:35

Quite similar to Pinguin Dirk's answer, but here it is:

v = {1 \[UndirectedEdge] 9, 1 \[UndirectedEdge] 10,
1 \[UndirectedEdge] 8, 10 \[UndirectedEdge] 2,
10 \[UndirectedEdge] 5, 9 \[UndirectedEdge] 3,
9 \[UndirectedEdge] 6, 8 \[UndirectedEdge] 7,
8 \[UndirectedEdge] 4, 7 \[UndirectedEdge] 3,
7 \[UndirectedEdge] 2, 6 \[UndirectedEdge] 2,
6 \[UndirectedEdge] 4, 5 \[UndirectedEdge] 3,
5 \[UndirectedEdge] 4};

vertexLabels = Table[n -> Placed[Column[{n, "foo"}, Center], Center],
{n, VertexCount[Graph[v]]}];

g = Graph[v, VertexLabels -> vertexLabels, VertexStyle -> White, VertexSize -> 0.5] • The problem with your answer & Pinguin Dirk's is that the OP would not really be able to say anything else than foo or some text. Plus, the OP would not be able to choose whether he wants more than one line or not. – Öskå Oct 2 '13 at 17:17