2

I had a problem with my genealogy tree (can be found here). Someone suggested to me in the comments to use forest package. I tried to convert it however I don't know if it is possible to apply the same style.

My forest tree: enter image description here My original tree: enter image description here

So, what i am trying to achieve is to make my forest looks like my genealogy tree. Also, i would like to keep the levels like what i did with the forest in order to fit more data easily.

My code:

    \documentclass{article}
    \usepackage[]{forest}
    %\usetikzlibrary{shadows,arrows.meta}

    \usepackage{pdflscape}
    \usepackage{genealogytree}
    \usepackage{tikz}
    \usetikzlibrary{positioning}
                \begin{document}
    \forestset{
        skip one/.style={
            replace by={
                [,
                shape=coordinate,
                l*=.25,
                append
                ]
            },
        },
    }
        \begin{landscape}
        \resizebox{\linewidth}{!}{      
                \begin{forest}
    for tree={
        parent anchor=south,
        child anchor=north,
        draw,
        thick,
        font=\small\sffamily,
        align=center,
        delay={
            where content={}{
                shape=coordinate,
            }{},
        },
    },
    before packing={
        for tree={
            if={isodd(n_children())}{
                for children={
                    if={equal(n,int((1+n_children("!u"))/2))}{
                        calign with current,
                    }{},
                },
            }{},
            edge path={
                \noexpand\path [draw, thick, \forestoption{edge}] (!u.parent anchor) -- ++(0,-5pt) |- ($(.child anchor) + (0,5pt)$) -- (.child anchor)\forestoption{edge label};
            },
        },
    },
                    [CERT Services, 
                        [Reactive,
                            [Incident handling , skip one, l*=3
                                [incident analysis], 
                                [incident response on-site], 
                                [incident response support], 
                                [incident response coordination ], 
                            ]
                            [Vulnerability Handling,
                                [Vulnerability analysis], 
                                [Vulnerability response ], 
                                [Vulnerability response coordination], 
                            ]
                            [Artifact Handling, , skip one, l*=5
                                [Artifact analysis], 
                                [Artifact response], 
                                [Artifact response coordination], 
                            ]
                        ]
    %                   [Proactive, skip one, l*=15
    %                       [Announcements], 
    %                       [Technology Watch], 
    %                       [Security Audits or Assessments], 
    %                       [Configuration and Maintenance ], 
    %                       [Development of Security Tools], 
    %                       [Intrusion Detection Services], 
    %                       [Security-Related Information Dissemination]
    %                   ]
    %                   [Quality Management
    %                       [Risk Analysis], 
    %                       [Business Continuity and Disaster Recovery Planning], 
    %                       [Security Consulting], 
    %                       [Awareness Building], 
    %                       [Education/Training], 
    %                       [Product Evaluation or Certification], 
    %                   ]
                ]
                \end{forest}

            }
    \end{landscape}

                \begin{landscape}
                    \begin{figure}[b]
                        \noindent\resizebox{\linewidth}{!}{
                            \begin{genealogypicture}[
                                processing=database,
                                database format=full,
                                info separators={\tcbline}{\tcbline}{}{},
                                category/.style={box={colback=red!20}}, % category
                                service/.style={box={colback=green!20}}, % a Service
                                realization/.style={box={colback=blue!20 }}, %Realization Technique
                                empty/.style={box={colback=white}}, %Realization Technique
                                edges={foreground={line width=1pt,black,->,},background={line width=2pt,white},}, %swing,
                                box={fit basedim=9pt,boxsep=2pt,segmentation style=solid,halign=center,valign=center,before upper=\parskip2pt,\gtrDBsex,{colback=gray!20}},%CATEGORY
                                %               node={ turn=right},
                                after tree={
                                    \node [draw,black,fill=red!20,text height=1em] (a) at (current bounding box.north east) {Category};
                                    \node [draw,black,fill=green!20,left=2mm of a] (b) {Service};
                                    \node [draw,black,fill=blue!20,left=2mm of b] (c) { Technique};             
                                }
                                ]
                                child{
                                    g{name={\textbf{CERT \\ Services}}}
                                    child{
                                        g[category]{name={\textbf{React Services}}, comment= {This is performed in the software}}
                                        child{
                                            g[category]{name={\textbf{Linux Kernel Features}}, comment= {A feature in Linux kernel used to provide security}}

                                            child {
                                                g[service]{name={\textbf{Incident Analysis}}, comment= {service explanation}}                                       
                                                c[realization]{name={\textbf{xxx}}, comment= {realization explanation}}
                                                c[realization]{name={\textbf{xxx}}, comment= {realization explanation}}                                     
                                            }
                                            child {
                                                g[service]{name={\textbf{Incident Response On-site}}, comment= {service explanation}}                                   
                                                c[realization]{name={\textbf{xxx}}, comment= {realization explanation}}
                                                c[realization]{name={\textbf{xxx}}, comment= {realization explanation}}                                     
                                            }
                                            child {
                                                g[service]{name={\textbf{Incident Response Support}}, comment= {service explanation}}                                   
                                                c[realization]{name={\textbf{xxx}}, comment= {realization explanation}}
                                                c[realization]{name={\textbf{xxx}}, comment= {realization explanation}}                                     
                                            }
                                            child {
                                                g[service]{name={\textbf{incident response coordination}}, comment= {service explanation}}                                  
                                                c[realization]{name={\textbf{xxx}}, comment= {realization explanation}}
                                                c[realization]{name={\textbf{xxx}}, comment= {realization explanation}}                                     
                                            }                                               
                                        }
                                        child{
                                            g[category]{name={\textbf{Vulnerability Handling}}, comment= {service explanation}}
                                                child {
                                                g[service]{name={\textbf{Vulnerability Analysis}}, comment= {service explanation}}                                      
                                                c[realization]{name={\textbf{xxx}}, comment= {realization explanation}}
                                                c[realization]{name={\textbf{xxx}}, comment= {realization explanation}}                                     
                                                }
                                                child {
                                                g[service]{name={\textbf{Vulnerability Response}}, comment= {service explanation}}                                      
                                                c[realization]{name={\textbf{xxx}}, comment= {realization explanation}}
                                                c[realization]{name={\textbf{xxx}}, comment= {realization explanation}}                                     
                                                }
                                                child {
                                                g[service]{name={\textbf{vulnerability Response Coordination}}, comment= {service explanation}}                                 
                                                c[realization]{name={\textbf{xxx}}, comment= {realization explanation}}
                                                c[realization]{name={\textbf{xxx}}, comment= {realization explanation}}                                     
                                                }                           
                                        }
                                        child{
                                            g[category]{name={\textbf{Artifact Handling}}, comment= {Configuration automation}}
                                            child {
                                                    g[service]{name={\textbf{Artifact Analysis}}, comment= {service explanation}}                                   
                                                c[realization]{name={\textbf{xxx}}, comment= {realization explanation}}
                                                c[realization]{name={\textbf{xxx}}, comment= {realization explanation}}                                     
                                            }
                                            child {
                                                    g[service]{name={\textbf{Artifact Response}}, comment= {service explanation}}                                   
                                                c[realization]{name={\textbf{xxx}}, comment= {realization explanation}}
                                                c[realization]{name={\textbf{xxx}}, comment= {realization explanation}}                                     
                                            }
                                            child {
                                                    g[service]{name={\textbf{Artifact Response Coordination}}, comment= {service explanation}}                              
                                                c[realization]{name={\textbf{xxx}}, comment= {realization explanation}}
                                                c[realization]{name={\textbf{xxx}}, comment= {realization explanation}}                                     
                                            }   
                                        }
                                    }
    %                               child{
    %                                   g[category]{name={\textbf{Proactive Services}}, comment= {This is performed in the hardware}}
    %                                   child {
    %                                       g[empty]{name={\textbf{x}}}
    %                                       child{
    %                                           g[empty]{name={\textbf{x}}}
    %                                           child   {
    %                                               g[empty]{name={\textbf{x}}}
    %                                               child {
    %                                                   g[service]{name={\textbf{xxx}}, comment= {service explanation}}                                         
    %                                                   c[realization]{name={\textbf{xxx}}, comment= {realization explanation}}
    %                                                   c[realization]{name={\textbf{xxx}}, comment= {realization explanation}}                                     
    %                                               }
    %                                               child {
    %                                                   g[service]{name={\textbf{xxx}}, comment= {service explanation}}                                         
    %                                                   c[realization]{name={\textbf{xxx}}, comment= {realization explanation}}
    %                                                   c[realization]{name={\textbf{xxx}}, comment= {realization explanation}}                                     
    %                                               }
    %                                               child {
    %                                                   g[service]{name={\textbf{xxx}}, comment= {service explanation}}                                         
    %                                                   c[realization]{name={\textbf{xxx}}, comment= {realization explanation}}
    %                                                   c[realization]{name={\textbf{xxx}}, comment= {realization explanation}}                                     
    %                                               }
    %                                               child {
    %                                                   g[service]{name={\textbf{xxx}}, comment= {service explanation}}                                         
    %                                                   c[realization]{name={\textbf{xxx}}, comment= {realization explanation}}
    %                                                   c[realization]{name={\textbf{xxx}}, comment= {realization explanation}}                                     
    %                                               }
    %                                               child {
    %                                                   g[service]{name={\textbf{xxx}}, comment= {service explanation}}                                         
    %                                                   c[realization]{name={\textbf{xxx}}, comment= {realization explanation}}
    %                                                   c[realization]{name={\textbf{xxx}}, comment= {realization explanation}}                                     
    %                                               }
    %                                               child {
    %                                                   g[service]{name={\textbf{xxx}}, comment= {service explanation}}                                         
    %                                                   c[realization]{name={\textbf{xxx}}, comment= {realization explanation}}
    %                                                   c[realization]{name={\textbf{xxx}}, comment= {realization explanation}}                                     
    %                                               }
    %                                               child {
    %                                                   g[service]{name={\textbf{xxx}}, comment= {service explanation}}                                         
    %                                                   c[realization]{name={\textbf{xxx}}, comment= {realization explanation}}
    %                                                   c[realization]{name={\textbf{xxx}}, comment= {realization explanation}}                                     
    %                                               }
    %                                           }
    %                                       }                   
    %                                   }
    %                               }
    %                               child{
    %                                   g[category]{name={\textbf{Security Quality Management Services}}, comment= {This is performed in the hardware}}
    %                                   c[service]{name={\textbf{xxx}}, comment= {service explanation}}
    %                                   c[service]{name={\textbf{xxx}}, comment= {service explanation}}
    %                                   c[service]{name={\textbf{xxx}}, comment= {service explanation}}
    %                                   c[service]{name={\textbf{xxx}}, comment= {service explanation}}
    %                                   c[service]{name={\textbf{xxx}}, comment= {service explanation}}
    %                                   c[service]{name={\textbf{xxx}}, comment= {service explanation}} 
    %                                   
    %                                   
    %                               }
                                }
                            \end{genealogypicture}
                    }
                    \end{figure}
                \end{landscape}
                \end{document}

Finally, I have commented someparts of both the genealogy tree and the forest because the result will be so big and will not fit. If there is a way to fit it in one page i would really appreciate it.

thank you,

5
  • What exactly do you want to change and what not? What do you count as 'style' and what as 'level'?
    – cfr
    Dec 1, 2017 at 0:04
  • So you are using a US letter paper layout with the default margins? Changing that will allow you to fit more: simply loading geometry will help. Moving to a country which uses A4 will help width-wise, but make things worse height-wise.
    – cfr
    Dec 1, 2017 at 0:07
  • I want to make the forest tree look like the genealogy tree. and arrange the nodes to fit (in the first photo for the forest i made it levels which i though could help) Dec 1, 2017 at 0:21
  • @cfr I've posted your last comment to chat so that it can get all the stars it truly deserves. :D
    – Alan Munn
    Dec 1, 2017 at 1:25
  • @AlanMunn So you get the stars for my comment? :-)
    – cfr
    Dec 1, 2017 at 2:03

1 Answer 1

3

This fits on landscape US letter, with geometry and includes the commented sections. It also avoids scaling the diagram, which is considered extremely icky.

Just loading geometry helps with fitting things in. Moving to a country which uses A4 might also help: it would make things better width-wise, but worse height-wise.

It changes the layout as there is no way to fit things otherwise, as far as I can see.

Unfortunately, it appears to currently be impossible to upload an image to the site. I guess things are broken again. So you'll have to compile yourself to see the results. OK. I guess the internet just had an existence failure, so that's OK. Here's the output.

\documentclass{article}
\usepackage[landscape]{geometry}
\usepackage[edges]{forest}
\forestset{declare boolean={switch me}{0}}
\begin{document}    
\begin{forest}
  where n children=0{!u.switch me}{},
  delay={
    where switch me={
      replace by/.process={ Ow {content} {{[#1, fit=rectangle, append]}}}, 
      no edge,
      shape=coordinate,
      content=,
      for tree={
        grow'=0,
      },
      for children={
        folder,
        edge path'={(!uu.parent anchor) |- (!.child anchor)},
      },
    }{},
  },
  before typesetting nodes={
    where level=0{fill=gray!20}{
      if level=1{fill=red!20}{
        if level=2{fill=green!20}{fill=blue!20},
      },
    },
    for tree={
      draw,
      thick,
      rounded corners,
      edge+={->,thick},
      align=center,
      font=\small\sffamily,
      parent anchor=children,
    },
    where switch me={
      for current and ancestors={
        edge path'={(!u.parent anchor) -- ++(0pt,-5pt) -| (.child anchor) }, % forked edge seems to get confused
        child anchor=parent,
      },
      for nodewalk={fake=1,descendants}{
        folder, 
        child anchor=west,
      }
    }{},
  },
  [CERT Services, 
      [Reactive,
          [Incident\\handling 
              [incident\\analysis], 
              [incident\\response\\on-site], 
              [incident\\response\\support], 
              [incident\\response\\coordination], 
          ]
          [Vulnerability\\Handling, calign with current edge
              [Vulnerability\\analysis], 
              [Vulnerability\\response ], 
              [Vulnerability\\response\\coordination], 
          ]
          [Artifact\\Handling, 
              [Artifact\\analysis], 
              [Artifact\\response], 
              [Artifact\\response\\coordination], 
          ]
      ]
      [Proactive, 
          [Announcements], 
          [Technology\\Watch], 
          [Security\\Audits or\\Assessments], 
          [Configuration\\\&\\Maintenance ], 
          [Development\\of Security\\Tools], 
          [Intrusion\\Detection\\Services], 
          [Security-Related\\Information\\Dissemination]
      ]
      [Quality\\Management
          [Risk\\Analysis], 
          [Business\\Continuity\\\& Disaster\\Recovery\\Planning], 
          [Security\\Consulting], 
          [Awareness\\Building], 
          [Education\\\& Training], 
          [Product\\Evaluation or\\Certification], 
      ]
]
\end{forest}
\end{document}

EDIT

Another possibility, which does not use folder and tries to make the nodes more uniform in size (as requested in comments) would look like this:

alternative

Note that the frame shows the text block (US letter with geometry default margins). It is not possible to make all the nodes the same size without making the diagram too tall for the page - or thinking up some other layout trick to push stuff around somehow else.

You just have to play with this kind of thing. In the end, you're in a better position to decide what trade-offs to make than anybody else. Together these two examples indicate what is possible relatively-out-of-the-box. Tweaks are something you have to play around with until you're happy. That is, not only are tweaks an exercise left to you, gentle reader. But tweaks of this kind are things of a kind which only thee can make.

\documentclass{article}
\usepackage[landscape,showframe]{geometry}
\usepackage[edges]{forest}
\forestset{
  ph me/.style={
    tier=#1,
    if n children=0{phantom}{edge+=-, shape=coordinate},
  },
  /tikz/.cd,
  col base/.style={fill=#1!20},
  moonie/.style={col base=red, minimum height=0pt},
  sonny/.style={col base=blue, minimum height=9ex},
  grassy/.style={col base=green, minimum height=9ex},
}
\begin{document}   
\noindent
\begin{forest}
  forked edges,
  for tree={
    draw,
    thick,
    rounded corners,
    edge+={->,thick},
    align=center,
    font=\small\sffamily,
    parent anchor=children,
    child anchor=parent,
    if level>=2{
      calign child=-1,
      calign=child edge,
      anchor=parent,
    }{},
  },
  before typesetting nodes={
    where content={}{shape=coordinate, edge+=-}{},
  },
  where level=0{col base=gray}{
    if level=1{moonie}{
      if level=2{grassy}{sonny},
    },
  },
  [CERT Services, 
      [Reactive,
          [Incident\\handling 
              [incident\\analysis]
              [incident\\response\\on-site]
              [incident\\response\\support]
              [incident\\response\\coordination, tier=cloud]
          ]
          [, ph me=cloud
            [Vulnerability\\Handling, grassy
              [Vulnerability\\analysis] 
              [Vulnerability\\response ]
              [Vulnerability\\response\\coordination, tier=sun] 
            ]
          ]
          [, ph me=sun
            [Artifact\\Handling, grassy
              [Artifact\\analysis] 
              [Artifact\\response]
              [Artifact\\response\\coordination, tier=here]
            ]
          ]
      ]
      [, ph me=here
      [Proactive, moonie, for children={grassy}
        [Announcements], 
        [Technology\\Watch], 
        [Security\\Audits or\\Assessments], 
        [Configuration\\\& Maintenance ], 
        [Development\\of Security\\Tools], 
        [Intrusion\\Detection\\Services], 
        [Security-Related\\Information\\Dissemination, tier=there]
      ]]
      [, ph me=there
      [Quality\\Management, moonie, for children=grassy
          [Risk\\Analysis], 
          [Business Continuity \&\\Disaster Recovery Planning], 
          [Security\\Consulting], 
          [Awareness\\Building], 
          [Education\\\& Training], 
          [Product Evaluation\\or Certification]
      ]]
]
\end{forest}
\end{document}
2
  • Thank you for your answer. Is it possible not to use folder. another thing is it possible to make all boxes have the same size. Lastly, since i am new to forest, how to set individual node style. Dec 1, 2017 at 21:01
  • @Sari Of course you can not use folder. But you wanted to fit everything on the page, so you need some space-efficient way of doing that. You can apply individual styles to the nodes in the usual way - just as you do in the code you posted in your question. I just removed stuff because it was mainly positioning and it was easier to work from the basic default layout. You can make the nodes the same size using e.g. text height, text width and text depth for the tree. Or minimum size and minimum width or whatever, if you're careful. Just do it as usual in TikZ - whatever works.
    – cfr
    Dec 2, 2017 at 1:41

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.