2

I am adapting the answer here to create a tree Diagram on 4 levels. I want to create the UML Diagram Types diagram in Latex like this:

UML diagram types

My code:

%https://tex.stackexchange.com/questions/50418/tools-for-tree-diagram/50426
%run with xelatex

\documentclass{article}
\usepackage{pst-tree,array}    
\pagenumbering{gobble}% Remove page numbers (and reset to 1)
\usepackage[margin=0pt]{geometry}% http://ctan.org/pkg/geometry  https://tex.stackexchange.com/questions/125937/is-there-any-other-margin-i-must-set-to-reduce-margin-to-zero
\begin{document}
\def\PSB#1{\pspicture(3,1.5)\psTextFrame[shadow,
    fillstyle=solid,linecolor=gray,fillcolor=pink!30,framearc=0.3](0,0)(3,1.5){
        \shortstack{#1}}\endpspicture}

%\pstree{<root>}{<successors>}



\def\psedge#1#2{\ncdiagg[nodesep=3pt,angleA=180,armA=0]{#2}{#1}}
\pstree[treemode=R,levelsep=*1cm]{\Tr{\PSB{Diagram}}}{
\pstree{\Tr{\PSB{Structure\\ Diagram}}}{\Tr{\PSB{Class  Diagram}} \Tr{\PSB{Composite \\ Structure Diagram}} \Tr{\PSB{Component Diagram}} \Tr{\PSB{Deployment Diagram}} \Tr{\PSB{Object Diagram}}   \Tr{\PSB{Package Diagram}}  }
\pstree{\Tr{\PSB{Behaviour\\ Diagram}}}{\pstree{\Tr{\PSB{Barry Santos}}}{\Tr{\PSB{James Kyle}} \Tr{\PSB{Ann Ada}}}}
\pstree{\Tr{\PSB{Behaviour\\ Diagram}}}{\pstree
                            {\pstree{\Tr{\PSB{Barry Santos}}}{\Tr{\PSB{James Kyle}} \Tr{\PSB{Ann Ada}}}}{\Tr{\PSB{James Kyle}} \Tr{\PSB{Ann Ada}}}}

}
\end{document} 

results in

UML diagram v1

How do I add more children to Behavior Diagram?

3
  • Welcome to TeX.SE! Can be drawn with some other package than pstree? For example with TikZ or Forest? Do you like that tree grow horizontally to right? – Zarko Mar 4 '17 at 20:25
  • Thank you! Can be drawn with any package, as long as I can grow the tree to the right. – iulia Mar 5 '17 at 9:47
  • then see, if my answer fulfill your expectation (both enabled grow to any deep level /to the right/). – Zarko Mar 5 '17 at 10:42
2

Edit: I'm not familiar with pst-tree and therefore I can only say that add child node to some child should be done on the same way as was done for child to which you like add child.

With packages tikz and forest, especial later the construction of trees are relatively simple with well designed structure.

Below are examples with both aforementioned packages. Their structures are partly follows to image, which you show as result of your MWE based on your MWE, partly on guessing what you like to obtain. Hopefully both can serve as starting point to design your real tree.

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{shadows, trees}

\begin{document}
    \begin{tikzpicture}[
every node/.style = {draw, rounded corners, fill=red!30,
    text width=18mm, minimum height=9mm, align=center,
    drop shadow},
             grow = right,
level distance = 27mm,
sibling distance=55mm,
growth parent anchor=east,
edge from parent path=(\tikzparentnode.east) -- (\tikzchildnode.west)
                        ]
\node   {Diagram}
    child{  node[yshift=11mm]{?? ??}}
%
    child{  node{Behaviour Diagram}
        [sibling distance=12mm]
        child{  node{Barry Santos}
            child{  node{James Kyle}}
            child{  node{Ann Ada}}
            child{  node{James Kyle}}
            child{  node{Ann Ada}}
             }
        child{  node{???}}
         }
%
    child{  node{Structure Diagram}
        [sibling distance=13mm]
        child{ node{Class  Diagram}}
        child{ node{Composite Structure Diagram}}
        child{ node{Component Diagram}}
        child{ node{Deployment Diagram}}
        child{ node{Object Diagram}}
        child{ node{Package Diagram}}
         }
    ;
    \end{tikzpicture}
\end{document}

enter image description here

Supremacy of forest over tikz trees demands more invest into learning, however, it is worth. Final result is nicer, code for placement of children is simpler and concise, etc.

Below are two version of trees, one with forged edges and the second similar as showed with tikz solution:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{shadows}
\usepackage[edges]{forest}

\begin{document}
   \begin{forest}
    for tree={% style of tree nodes
      draw, semithick, rounded corners, drop shadow,
        top color = red!20,
     bottom color = red!40,
       text width = 18mm, text badly centered,
              % style of tree (edges, distances, direction)
             edge = {draw, semithick},
           anchor = east,
             grow = east,
    forked edge,            % for forked edge
            s sep = 4mm,    % sibling distance
            l sep = 8mm,    % level distance
         fork sep = 4mm,    % distance from parent to branching point
               }
[Diagram
    [?? ??]
%
    [Behaviour Diagram
        [Barry Santos
            [Ann Ada]
            [James Kyle]
            [Ann Ada]
            [James Kyle]
        ]
        [???]
    ]
%
    [Structure Diagram
        [Class  Diagram]
        [Composite Structure Diagram]
        [Component Diagram]
        [Deployment Diagram]
        [Object Diagram]
        [Package Diagram]
    ]
]
    \end{forest}
\end{document}

enter image description here

Here is partly considered OP comment regarding node design:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{shadows}
\usepackage[edges]{forest}

\begin{document}
   \begin{forest}
    for tree={% style of tree nodes
      draw, semithick, rounded corners, drop shadow,
        top color = red!20,
     bottom color = red!40,
       text width = 33mm, text badly centered,% <-- "align=center" doesn't work
              % style of tree (edges, distances, direction)
             edge = {draw, semithick},
    parent anchor = east, 
     child anchor = west,
             grow = east,
            s sep = 4mm,    % sibling distance
            l sep = 8mm,    % level distance
               }
[Diagram
    [?? ??]
%
    [Behaviour Diagram
        [Barry Santos
            [Ann Ada]
            [James Kyle]
            [Ann Ada]
            [James Kyle]
        ]
        [???]
    ]
%
    [Structure Diagram
        [Class  Diagram]
        [Composite Structure Diagram]
        [Component Diagram]
        [Deployment Diagram]
        [Object Diagram]
        [Package Diagram]
    ]
]
    \end{forest}
\end{document}

enter image description here

2
  • Adapted your solution and it is perfect: \documentclass[tikz, margin=3mm]{standalone} \usetikzlibrary{shadows, trees} \begin{document} \begin{tikzpicture}[ every node/.style = {draw, rounded corners, fill=blue!40!white, text width=35mm, minimum height=9mm, align=center, drop shadow}, grow = right, level distance = 37mm, sibling distance=75mm, growth parent anchor=east, edge from parent path=(\tikzparentnode.east) -- (\tikzchildnode.west) ] – iulia Mar 5 '17 at 11:44
  • @iulia, with tikz tree you need with change of node size -- as you figured out -- also change sibling and level distances. This is not a case with forest. To demonstrate this, I add second solution with forest, where I consider your node size changes. Of course, in forest you can use simpler fill=... instead of topcolor=..., bottom color .... – Zarko Mar 5 '17 at 13:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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