Hallo Leute, ich habe mit meinem Diagramm ein Problem. Der nachfolgende Code ist ok und ergibt folgendes 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} 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! |
Der Stil \tikzstyle{edge from parent fork down}= [edge from parent path={(\tikzparentnode\tikzparentanchor) -- +(0pt,-.5\tikzleveldistance) -| (\tikzchildnode\tikzchildanchor)}] definiert. Dabei ist \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 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 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} beantwortet 04 Nov '15, 10:46 esdd |
"Tiki"? Ok... :()