Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

This question already has an answer here:

I need to display arbitrary Expressions in TreeForm, but the standard vertical layout produces too many horizontally overlapping boxes. Am I doomed to rewriting expressions as graphs and using TreePlot and GraphPlot and going down this road

http://www.wolfram.com/technology/guide/FullyAutomatedGraphLayout/

or is there something I can do in a hurry to make TreeForm look better?

Docs say

TreeForm takes the same options as TreePlot. 

so I pop over to TreePlot and see

TreePlot[{1 -> 4, 1 -> 6, 1 -> 8, 2 -> 6, {3 -> 8, "3\[Rule]8"}, 
  4 -> 5, 7 -> 8}, Left]

go back to TreeForm and try

TreeForm[a + b^2 + c^3 + d, Left]

but oops:

TreeForm::tlev: Warning: level specification Left is not a non-negative integer or
Infinity; ignored. >>
share|improve this question

marked as duplicate by bobthechemist, belisarius, rasher, Sjoerd C. de Vries, m_goldberg Apr 11 at 21:30

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2  
Isn't this a duplicate of Can TreeForm be displayed “sideways”? –  Rahul Apr 11 at 0:48
1  
Left is not an option, it's a parameter. –  Sjoerd C. de Vries Apr 11 at 20:33

2 Answers 2

up vote 10 down vote accepted

Generally - arbitrary-angle layout:

Rotate[ ... /. x_Framed -> Rotate[x, -angle], angle]

enter image description here

Now you can do it like this:

Rotate[ToExpression@ToBoxes@TreeForm[a + b^2 + c^3 + d] /. 
  x_Framed -> Rotate[x, -Pi/2], Pi/2]

Or like this:

enter image description here

P.S. =========================

Manipulate code for the record

Manipulate[Show[Rasterize@
   Rotate[ToExpression@ToBoxes@TreeForm[a + b^2 + c^3 + d] /. 
     x_Framed -> Rotate[x, -ang], ang],
  ImageSize -> 200 {1, 1}],
 {ang, 0, 2 Pi}]
share|improve this answer
    
ouch...totally ignored Rotate. yes, that makes absolutely sense. –  Stefan Apr 10 at 19:39
    
This is a really good instance of "thinking out of the box" -- composing some generic but display-specific functions (/slaps forehead) –  Reb.Cabin Apr 10 at 20:54
    
Interesting that the Rotate works when the TreeForm graphic is pasted directly into the Rotate call, but the following does not work (because it doesn't rotate the internal framed bits) Rotate[TreeForm[a+b^2+c^3+d], /. x_Framed -> Rotate[Framed[x], -Pi/2], Pi/2] –  Reb.Cabin Apr 10 at 21:17
1  
This code adds an extra frame. You only need Rotate[ ... /. x_Framed -> Rotate[x, -Pi/2], Pi/2] –  ArgentoSapiens Apr 10 at 22:04
    
@ArgentoSapiens thank you, corrected. –  Vitaliy Kaurov Apr 11 at 14:43

I don't know if this is by any means what you're looking for, but you can use VertexCoordinateRules to determine the coordinates at which vertices should be placed:

TreeForm[a + b^2 + c^3 + d, 
    VertexCoordinateRules -> {{1, 4}, {2, 8}, {3, 8}, {4, 10}, {4, 6}, {3, 0}, 
        {4, 3}, {4, -2}, {2, 0}}]

enter image description here

share|improve this answer

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