1

I'm having a bit of trouble with a diagram. I can't figure out how to get the fork from the second node to the 6th node at the same level and have the text not overlapping.

\documentclass[a4paper,12pt]{report}
\begin{tikzpicture}
    \node {Sous-préfet}
        [style=edge from parent fork down]
        [level distance=5cm]
        child {
            node {Secrétaire Général}
            [level distance=5cm]
            child { node {Bureau de la sécurité et des titres} }
            child { node {Bureau de l'ingénierie territorial} }
        }
        child { node {Secrétariat particulier} }
    ;

It looks like this at the moment :

enter image description here

The end product I'm going for is something like this (without the colour) :

enter image description here

2
  • 3
    Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. Jun 4, 2016 at 9:56
  • Please make your code compilable as requested. The edited code cannot possibly compile for you without error!
    – cfr
    Jun 4, 2016 at 13:33

2 Answers 2

1

If forest is an option, it will automatically figure out the spacing for you.

\documentclass[tikz,border=10pt,multi]{standalone}
\usepackage{array}
\usepackage[edges]{forest}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\begin{document}
\begin{forest}
  forked edges,
  for tree={
    align={c},
    inner xsep=0pt,
    draw,
  }
  [Sous-préfet
    [Secrétaire Général, calign with current edge
      [Bureau de la sécurité et des titres\\\hline Something further here\\\hline And some more
      ]
      [Bureau de l'ingénierie territorial\\\hline {More here, too}\\\hline Yet further stuff\\\hline Some final thoughts
      ]
    ]
    [Secrétariat particulier, no edge, tikz+={\draw [\forestoption{edge}] (.west) -- (!s.east);}
    ]
  ]
\end{forest}
\end{document}

Forest solution

EDIT

For version 1 of Forest, replace

\usepackage[edges]{forest}

by

\usepackage{forest}

and

  forked edges,
  for tree={
    align={c},
    inner xsep=0pt,
    draw,
  }

with

  for tree={
    align={c},
    inner xsep=0pt,
    draw,
    edge path={%
      \noexpand\path [\forestoption{edge}] (!u.parent anchor) -- ++(0,-5pt) -| (.child anchor)\forestoption{edge label};},
  }

which should work unless I've made a typo.

5
  • Trying to add this to my document but I'm getting compile errors in Main.tex for some reason. I added the userpackages but nothing. I'm using Overleaf.
    – AlexTDS1
    Jun 4, 2016 at 14:19
  • Oh, yes. Overleaf has an outdated version of TeX Live with an old version of Forest.
    – cfr
    Jun 4, 2016 at 15:31
  • Please see edit above.
    – cfr
    Jun 4, 2016 at 15:35
  • Got it working, just needed to edit to : \noexpand\path [\forestoption{edge}] (!u.parent anchor) -- ++(0,-19pt) to get the lines right. Thanks for your help !
    – AlexTDS1
    Jun 4, 2016 at 16:25
  • Oh, yes. Sorry. I should have pointed out you might need to tweak the dimension.
    – cfr
    Jun 4, 2016 at 16:31
1

It seems that you for sibling distance use level distance ... See, if the following code gives what you looking for:

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{trees}
\usepackage[utf8]{inputenc}

\begin{document}
     \begin{tikzpicture}[
edge from parent fork down,
 sibling distance = 44mm,
   level distance = 22mm,
every node/.style = {text width=33mm, inner sep=1mm,  
                     anchor=north, align=flush center}
                    ]
    \node {Sous-préfet}
         child {
            node {Secrétaire\\ Général}
            child { node {Bureau de la sécurité et des titres} }
            child { node {Bureau de l'ingénierie territorial} }
        }
        child { node {Secrétariat particulier} }
    ;
    \end{tikzpicture}    
\end{document}

enter image description here

1
  • 1
    I'm sorry, I forgot this and also didn't check his/her reputation ... I will erase my comment.
    – Zarko
    Jun 4, 2016 at 13:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .