Skip to article content

Arrange a tree for a readable diagram

Changing a tree's root changes how its branches appear. Use the guide's weighted tree to choose a readable layout while keeping the connections intact.

Check the editor stepsSamples and layouts

Four vertices and weighted edges

The header 4 3 gives four vertices and three edges: 1–2, 1–3, and 3–4. Every vertex is connected and there is no cycle, so this graph is a tree.

The third column contains the weights 5, 2, and 7. They can represent distances or costs. They do not specify a vertex's height or depth in the diagram.

Choose a root to follow the branches

The Tree layout places root 1 above vertices 2 and 3, with vertex 4 below 3. Edge weights are preserved.
The Tree layout places root 1 above vertices 2 and 3, with vertex 4 below 3. Edge weights are preserved. (Japanese interface.)

With vertex 1 as the root, 2 and 3 are its children and 4 sits below 3. With vertex 3 as the root, 1 and 4 are its children and 2 sits below 1. The parent-child relationships depend on the root.

Select one vertex before choosing Tree in Layouts to use it as the root. Changing the root keeps all connections and edge weights intact.

Leave room for labels and weights

After applying a layout, check that vertex labels and edge weights do not overlap. Move vertices to adjust tight areas and check that labels remain readable at the size you plan to use.

Tree layout is unavailable for graphs with cycles. Read the displayed reason when a layout is disabled, then choose another layout suited to the graph's connections.

Compare the input and diagram

Input to copy

4 3
1 2 5
1 3 2
3 4 7

Graph diagram

5271234
A tree with 4 vertices and 3 edges: 1–2 has weight 5, 1–3 has weight 2, and 3–4 has weight 7.

Related articles

Back to all articles