The answer to this question will depend on which pdf library you are using to generate your files. In general, you will need to produce a file that has an Order array in the optional content configuration dictionary that represents the tree that you want to display.
From the PDF Reference Document:
Key: Order
Type: array
Description: (Optional) An array specifying the order for presentation of optional content groups in a conforming reader’s user interface. The array elements may include the following objects:
-Optional content group dictionaries, whose Name entry shall bedisplayed in the user interface by the conforming reader.
-Arrays of optional content groups which may be displayed by a conforming reader in a tree or outline structure. Each nested array may optionally have as its first element a text string to be used as a non-selectable label in a conforming reader’s user interface.