11

I want to draw this scheme

enter image description here

so I made this code

\begin{tikzpicture}[
every node/.style = {shape=rectangle, rounded corners,
                     draw, font=\small, align=center, fill=white},              
   level 1/.style = {sibling distance = 10em},% <-- new
   level 2/.style = {sibling distance = 9em},% <-- new
   level 3/.style = {sibling distance = 8em},% <-- new
   level 4/.style = {sibling distance = 8em},% <-- new
]
\node {Estabilidade de Sistemas\\Elétricos de Potência}
    [edge from parent fork down]
    child {node {Estabilidade do\\Ângulo do Rotor}
        child {node {Estabilidade Angular\\a Pequenos Distúrbios}}
        child {node {Estabilidade\\Transitória}
            child {node {Curto Prazo}}}}
    child {node{Estabilidade de\\Frequência}
        child{node{Curto Prazo}}
        child{node{Longo Prazo}}}
    child {node{Estabilidade\\de Tensão}
           child {node{Estabilidade de\\Tensão a Grandes\\Perturbações}
                child {node{Curto Prazo}}}
           child {node {Estabilidade de\\Tensão a Pequenas\\Perturbações}
                child {node{Longo Prazo}}}};
\end{tikzpicture}

But I'm getting this

enter image description here

I don't know how to make two nodes have the same childs and make the correct vertical spacings.

Please, help me!

2
  • 1
    Welcome! Would using forest be an option?
    – user194703
    Oct 28, 2019 at 16:35
  • 1
    This is not formally a tree, so you'll have to do some manual work to make multidominant roots. But the base tree methods in TikZ are unfortunately never ideal, since they do no automatic positioning. As @Schrödinger'scat suggests, it would be better to use forest. But since this is not a tree see e.g. Lost in the Forest -- Merging after Branching? for some ideas.
    – Alan Munn
    Oct 28, 2019 at 17:16

2 Answers 2

11

This is not a perfect solution. Used missing child to ‘make’ two nodes have the same child.

enter image description here

\documentclass[border=3mm]{standalone}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{trees}

\begin{document}

\begin{tikzpicture}[
every node/.style = {shape=rectangle, rounded corners,
                     draw, font=\small, align=center, fill=white},              
   level 1/.style = {sibling distance = 10em},% <-- new
   level 2/.style = {sibling distance = 9em},% <-- new
   level 3/.style = {sibling distance = 8em},% <-- new
   level 4/.style = {sibling distance = 8em},% <-- new
]
\node {Estabilidade de Sistemas\\Elétricos de Potência}
    [edge from parent fork down]
    child {node {Estabilidade do\\Ângulo do Rotor}
        child {node {Estabilidade Angular\\a Pequenos Distúrbios}
child[missing] child{}}
        child {node {Estabilidade\\Transitória}
            child {node[xshift=-3.6mm] {Curto Prazo}}child[missing]}}
    child {node{Estabilidade de\\Frequência}
child{child{
        child{node{Curto Prazo}}
        child{node{Longo Prazo}}}}}
    child {node{Estabilidade\\de Tensão}
           child {node{Estabilidade de\\Tensão a Grandes\\Perturbações}
                child[missing]  child[missing] child {node{Curto Prazo}}}
           child {node {Estabilidade de\\Tensão a Pequenas\\Perturbações}
                child {node{Longo Prazo}}child[missing] child[missing]
}};
\end{tikzpicture}

\end{document}
3
  • 1
    Thanks a lot! That's exactly what I was looking for! Oct 28, 2019 at 19:23
  • 3
    Just a quick note: include \usepackage[T1]{fontenc} so the accented glyphs are visible. :) Oct 28, 2019 at 19:30
  • Thanks for the update! I wish I could +1 again! :) Oct 28, 2019 at 19:43
8
\documentclass[border=12pt]{standalone}

\usepackage[edges]{forest}


\begin{document}


\begin{forest}
  for tree={align=c,draw,rounded corners, tier/.option=level, anchor=base, l sep'+=10pt},
  forked edges,
  before typesetting nodes={
    where content={}{phantom}{}
  },
  before drawing tree={
    where n children=0{
      if={>O{!u.phantom}}{
        tikz+={\draw (!up.parent anchor) -- +(0pt,-\foresteoption{fork sep}) -| (.child anchor) (!un.parent anchor) -- +(0pt,-\foresteoption{fork sep}) -| (.child anchor);}
      }{}
    }{}
  },
  [Estabilidade de Sistemas\\Elétricos de Potência
    [Estabilidade do\\Ângulo do Rotor
      [Estabilidade Angular\\a Pequenos Distúrbios[]]
      [ 
        [Curto Prazo]
      ]
      [Estabilidade\\Transitória[]]
    ]
    [Estabilidade de\\Frequência
    [\strut\\\strut\\\strut, draw=none, child anchor/.option=parent anchor 
        [Curto Prazo]
        [Longo Prazo]
      ]
    ]
    [Estabilidade\\de Tensão
      [Estabilidade de\\Tensão a Grandes\\Perturbações[]]
      [
        [Curto Prazo]
        [Longo Prazo]
      ]
      [Estabilidade de\\Tensão a Pequenas\\Perturbações[]]
    ]
  ]
\end{forest}

\end{document}

output

3
  • 1
    Thanks! It is a good alternative to solve the problem! Oct 28, 2019 at 19:25
  • 1
    Nice answer, as always! +1 from me, cwac! :) Oct 28, 2019 at 19:43
  • @PauloCereda Cwac cwac ;). Diolch yn fawr!
    – cfr
    Oct 28, 2019 at 21:24

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.