TreePlot EdgeLabeling Style
The labels are implemented in terms of Arrowheads
and Inset
in a rather strange way. One fix is to render the labels manually with a custom EdgeRenderingFunction
:
TreePlot[edges2, BaseStyle -> 20,
EdgeRenderingFunction ->
({Line[#1], If[#3 === None, {}, Text[Panel@#3, Mean@#1]]} &)
]
Regarding the default rendering, an arrowhead normally points in the direction of the arrow and therefore the labels, implemented as Arrowheads, would also point in the direction of the line. The fifth argument of Inset
is used to compensate for this but the implementation is flawed. You can see the default alignment with:
TreePlot[edges2, BaseStyle -> 20] /.
Inset[a_, b_, c_, d_, DIR_, opts__] :> Inset[a, b, c, d, opts]
Solution
We can correct the fifth argument from None
to {None, None}
like this:
edges = {{1 -> 2, "Test"}, {1 -> 3, "Test"}, {2 -> 14,
"Test"}, {3 -> 4, "Test"}, {4 -> 99, "Test"}, {3 -> 6,
"Test"}, {6 -> 7, "Test"}, {6 -> 8, "Test"}, {7 -> 9,
"Test"}, {8 -> 10, "Test"}, {8 -> 11, "Test"}, {10 -> 12,
"Test"}, {11 -> 13, "Test"}};
edges[[All, 2]] = Map[Panel[Style[#, 12], FrameMargins -> 2] &, edges[[All, 2]]];
TreePlot[edges, Top, 1, AspectRatio -> 1/3] /.
Inset[a__, None, opts___] :> Inset[a, {None, None}, opts]
This seems to me to be a bug with AspectRatio in the graphic boxes
TreePlot[edges2, AspectRatio -> 2]
works for this example, so try for your more complicated example (which you should post the code for) try
DeleteCases[TreePlot[edges3, EdgeLabeling -> True], AspectRatio -> _]