Hallo Leute,

ich habe mit meinem Diagramm ein Problem. Der nachfolgende Code ist ok und ergibt folgendes Diagramm.

Diagramm

Open in Online-Editor
  \documentclass[10pt]{article}
    \usepackage[utf8]{inputenc}
    \usepackage[landscape,paper=ansibpaper]{geometry}
    \usepackage{tikz}
    \usetikzlibrary{trees}
    \usetikzlibrary{shadings}
    \tikzstyle{every node}=[draw=black,thin,anchor=west, minimum height=2.5em]

    \begin{document}

    \begin{figure}[!htb]
    \resizebox{\linewidth}{!}{

    \begin{tikzpicture}[
        supervisor/.style={%
            edge from parent fork down,
            level distance=2.5cm,
        text centered, text width=5cm},
    teammate/.style={%
        text centered, text width=3cm,
        level distance=2.5cm,
        fill=gray!10},
    subordinate/.style={%
        grow=down, xshift=-1.1cm, % Horizontal position of the child node
        text centered, text width=3cm,
        edge from parent path={(\tikzparentnode.205) |- (\tikzchildnode.west)}},
    level1/.style ={level distance=1.5cm},
    level2/.style ={level distance=3cm},
    level3/.style ={level distance=4.5cm},
    level4/.style ={level distance=6cm},
    level5/.style ={level distance=7.5cm},
    level 1/.style={sibling distance=4cm},
    level 1/.append style={level distance=4.5cm},
]
%   \draw[help lines] (0,0) grid (4,3);

    % Supervisor
    \node[anchor=south,supervisor]{Supervisor\\Supervisory position\\Location}
    [edge from parent fork down]

    % Teammate and Subordinates
    child{node [teammate] {Teammate1\\Position1\\Location1}
        child[subordinate,level1] {node {Subordinate\\Position1\\Location1}}
        child[subordinate,level2] {node {Subordinate2}}
        child[subordinate,level3] {node {Subordinate3}}
        child[subordinate,level4] {node {Subordinate4\\Position4\\Location4}}
        child[subordinate,level5] {node {Subordinate5\\Position5\\Location5}}}
    %
    child{node [teammate] {Teammate2\\Position2\\Location2}
        child[subordinate,level1] {node {Subordinate1}}
        child[subordinate,level2] {node {Subordinate2}}
        child[subordinate,level3] {node {Third\\Teammate}}
        child[subordinate,level4] {node {Longtext-\\teammate}}}
    %
    child{node [teammate] {Teammate3\\Position3\\Location3}
        child[subordinate,level1] {node {Subordinate\\two lines}}
        child[subordinate,level2] {node {Subordinate2}}     
        child[subordinate,level3] {node {Subordinate3}}}
    %
    child{node [teammate] {Teammate4\\Position4\\Location4}
        child[subordinate,level1] {node {Subordinate1}}
        child[subordinate,level2] {node {Subordinate2}}}
    %
    child{node [teammate] {Teammate5\\Position5\\Location5}
        child[subordinate,level1] {node {First\\Subordinate}}
        child[subordinate,level2] {node {Subordinate2}}
        child[subordinate,level3] {node {Third\\Teammate}}
        child[subordinate,level4] {node {Longtext-\\teammate}}};

%\shade[shading=Mandelbrot set] (0,0) rectangle (5,5);
\end{tikzpicture}}
\caption{This is an org chart}
\end{figure}

\end{document}

Das Problem beginnt, wenn ich den Höhe des "Teammates" mit minimum height erhöhe und gleichzeitig level distance(level 1/.append style={level distance=4.5cm},). Nämlich zwischen dem "Supervisor" und dem "Teammate" ist der Knoten nicht mehr vertikal zentriert.

Also folgender Code ergibt das nachfolgende Bild:

Open in Online-Editor
\documentclass[10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[landscape,paper=ansibpaper]{geometry}
\usepackage{tikz}
\usetikzlibrary{trees}
\usetikzlibrary{shadings}
\tikzstyle{every node}=[draw=black,thin,anchor=west, minimum height=3em]

\begin{document}

\begin{figure}[!htb]
\resizebox{\linewidth}{!}{

\begin{tikzpicture}[
    supervisor/.style={%
        edge from parent fork down,
        level distance=2.5cm,
        text centered, text width=5cm},
    teammate/.style={%
        text centered, text width=3cm,
        level distance=2.5cm,
        minimum height=4cm,
        fill=gray!10},
    subordinate/.style={%
        grow=down, xshift=-1.1cm, % Horizontal position of the child node
        text centered, text width=3cm,
        edge from parent path={(\tikzparentnode.205) |- (\tikzchildnode.west)}},
    level1/.style ={level distance=1.5cm},
    level2/.style ={level distance=3cm},
    level3/.style ={level distance=4.5cm},
    level4/.style ={level distance=6cm},
    level5/.style ={level distance=7.5cm},
    level 1/.style={sibling distance=4cm},
    level 1/.append style={level distance=5cm},
]
%   \draw[help lines] (0,0) grid (4,3);

    % Supervisor
    \node[anchor=south,supervisor]{Supervisor\\Supervisory position\\Location}
    [edge from parent fork down]

    % Teammate and Subordinates
    child{node [teammate] {Teammate1\\Position1\\Location1}
        child[subordinate,level1] {node {Subordinate\\Position1\\Location1}}
        child[subordinate,level2] {node {Subordinate2}}
        child[subordinate,level3] {node {Subordinate3}}
        child[subordinate,level4] {node {Subordinate4\\Position4\\Location4}}
        child[subordinate,level5] {node {Subordinate5\\Position5\\Location5}}}
    %
    child{node [teammate] {Teammate2\\Position2\\Location2}
        child[subordinate,level1] {node {Subordinate1}}
        child[subordinate,level2] {node {Subordinate2}}
        child[subordinate,level3] {node {Third\\Teammate}}
        child[subordinate,level4] {node {Longtext-\\teammate}}}
    %
    child{node [teammate] {Teammate3\\Position3\\Location3}
        child[subordinate,level1] {node {Subordinate\\two lines}}
        child[subordinate,level2] {node {Subordinate2}}     
        child[subordinate,level3] {node {Subordinate3}}}
    %
    child{node [teammate] {Teammate4\\Position4\\Location4}
        child[subordinate,level1] {node {Subordinate1}}
        child[subordinate,level2] {node {Subordinate2}}}
    %
    child{node [teammate] {Teammate5\\Position5\\Location5}
        child[subordinate,level1] {node {First\\Subordinate}}
        child[subordinate,level2] {node {Subordinate2}}
        child[subordinate,level3] {node {Third\\Teammate}}
        child[subordinate,level4] {node {Longtext-\\teammate}}};

%\shade[shading=Mandelbrot set] (0,0) rectangle (5,5);
\end{tikzpicture}}
\caption{This is an org chart}
\end{figure}

\end{document}

alt text

Meine Frage ist nun, wie bekomme ich den Knoten immer mittig zwischen den Node'? Ich habe jetzt die darunterlegenden level nicht angepasst, wollte nur den oberen Fehler rekonstruieren.

Vielen Dank!

gefragt 04 Nov '15, 03:22

MCBR's gravatar image

MCBR
71336
Akzeptiert-Rate: 0%

bearbeitet 10 Nov '15, 13:17

esdd's gravatar image

esdd
17.8k284257

"Tiki"? Ok... :()

(04 Nov '15, 04:00) cis

Der Stil edge from parent fork down ist in der TikZ Bibliothek trees als

\tikzstyle{edge from parent fork down}=
  [edge from parent path={(\tikzparentnode\tikzparentanchor) -- +(0pt,-.5\tikzleveldistance)  -| (\tikzchildnode\tikzchildanchor)}]

definiert. Dabei ist \tikzleveldistance der vertikale Abstand zwischen dem Mittelpunkt des Elternknotens und dem Anker des Kindknotens. Soll die Verzweigung nun in der vertikalen Mitte zwischen Eltern- und Kindknoten stattfinden, kann man sich einen eigenen Stil dafür definieren

\usetikzlibrary{calc}
\tikzset{
  my edge from parent fork down half way/.style={
    edge from parent path={
      (\tikzparentnode\tikzparentanchor)
      -- ($(\tikzparentnode.south)!0.5!(\tikzchildnode.north-|\tikzparentnode.south)$)
      -| (\tikzchildnode\tikzchildanchor)
    }}
  }

Allerdings sollte man dann dafür sorgen, dass alle Knoten der entsprechenden child Ebene gleich hoch sind. Erreichen lässt sich das durch eine ausreichend große Mindesthöhe.

alt text

Code:

\documentclass[margin=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\tikzset{
  my edge from parent fork down/.style={
    edge from parent path={
      (\tikzparentnode\tikzparentanchor)
      -- ($(\tikzparentnode.south)!0.5!(\tikzchildnode.north-|\tikzparentnode.south)$)
      -| (\tikzchildnode\tikzchildanchor)
    }}
  }

\begin{document}
\begin{tikzpicture}[
    nodes={draw=black, thin,minimum height=3em},
    supervisor/.style={%
        text centered, text width=5cm},
    teammate/.style={%
        text centered, text width=3cm,
        minimum height=4cm,
        fill=gray!10},
    level 1/.style={sibling distance=4cm,level distance=5cm},
]
     %Supervisor
    \node[anchor=south,supervisor]{Supervisor\\Supervisory position\\Location}
    [my edge from parent fork down]
     %Teammate
    child{node [teammate] {Teammate1\\Position1\\Location1}}
    child{node [teammate
        %,minimum height=2cm
    ] {Teammate2\\Position2\\Location2}}
    child{node [teammate] {Teammate3\\Position3\\Location3}}
    child{node [teammate] {Teammate4\\Position4\\Location4}}
    child{node [teammate] {Teammate5\\Position5\\Location5}}
;
\end{tikzpicture}
\end{document}

Oder mit Deinen weiteren Ebenen

alt text

Code:

\documentclass[margin=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\tikzset{
  my edge from parent fork down/.style={
    edge from parent path={
      (\tikzparentnode\tikzparentanchor)
      -- ($(\tikzparentnode.south)!0.5!(\tikzchildnode.north-|\tikzparentnode.south)$)
      -| (\tikzchildnode\tikzchildanchor)
    }}
  }

\begin{document}

\begin{tikzpicture}[
    nodes={draw=black, thin,minimum height=3em},
    supervisor/.style={%
        text centered, text width=5cm},
    teammate/.style={%
        text centered, text width=3cm,
        minimum height=4cm,anchor=north,
        fill=gray!10},
    subordinate/.style={%
        anchor=west,
        grow=down, xshift=-1.1cm, % Horizontal position of the child node
        text centered, text width=3cm,
        edge from parent path={([xshift=-1.375cm]\tikzparentnode.south) |- (\tikzchildnode.west)}},
    level1/.style ={level distance=3.5cm},
    level2/.style ={level distance=5cm},
    level3/.style ={level distance=6.5cm},
    level4/.style ={level distance=8cm},
    level5/.style ={level distance=9.5cm},
    level 1/.style={sibling distance=4cm,level distance=5cm},
]
    % Supervisor
    \node[anchor=south,supervisor]{Supervisor\\Supervisory position\\Location}
    [my edge from parent fork down]
    % Teammate and Subordinates
    child{node [teammate] {Teammate1\\Position1\\Location1}
        child[subordinate,level1] {node {Subordinate\\Position1\\Location1}}
        child[subordinate,level2] {node {Subordinate2}}
        child[subordinate,level3] {node {Subordinate3}}
        child[subordinate,level4] {node {Subordinate4\\Position4\\Location4}}
        child[subordinate,level5] {node {Subordinate5\\Position5\\Location5}}}
    child{node [teammate] {Teammate2\\Position2\\Location2}
        child[subordinate,level1] {node {Subordinate1}}
        child[subordinate,level2] {node {Subordinate2}}
        child[subordinate,level3] {node {Third\\Teammate}}
        child[subordinate,level4] {node {Longtext-\\teammate}}}
    child{node [teammate] {Teammate3\\Position3\\Location3}
        child[subordinate,level1] {node {Subordinate\\two lines}}
        child[subordinate,level2] {node {Subordinate2}}     
        child[subordinate,level3] {node {Subordinate3}}}
    child{node [teammate] {Teammate4\\Position4\\Location4}
        child[subordinate,level1] {node {Subordinate1}}
        child[subordinate,level2] {node {Subordinate2}}}
    child{node [teammate] {Teammate5\\Position5\\Location5}
        child[subordinate,level1] {node {First\\Subordinate}}
        child[subordinate,level2] {node {Subordinate2}}
        child[subordinate,level3] {node {Third\\Teammate}}
        child[subordinate,level4] {node {Longtext-\\teammate}}};
\end{tikzpicture}
\end{document}
Permanenter link

beantwortet 04 Nov '15, 10:46

esdd's gravatar image

esdd
17.8k284257
Akzeptiert-Rate: 62%

bearbeitet 17 Sep '21, 22:33

Deine Antwort
Vorschau umschalten

Folgen dieser Frage

Per E-Mail:

Wenn sie sich anmelden, kommen Sie für alle Updates hier in Frage

Per RSS:

Antworten

Antworten und Kommentare

Markdown-Grundlagen

  • *kursiv* oder _kursiv_
  • **Fett** oder __Fett__
  • Link:[Text](http://url.com/ "Titel")
  • Bild?![alt Text](/path/img.jpg "Titel")
  • nummerierte Liste: 1. Foo 2. Bar
  • zum Hinzufügen ein Zeilenumbruchs fügen Sie einfach zwei Leerzeichen an die Stelle an der die neue Linie sein soll.
  • grundlegende HTML-Tags werden ebenfalls unterstützt

Frage-Themen:

×731
×76
×7

gestellte Frage: 04 Nov '15, 03:22

Frage wurde gesehen: 15,858 Mal

zuletzt geändert: 17 Sep '21, 22:33