直线到 tikzpicture 中的下线

直线到 tikzpicture 中的下线

如图所示,第二层和第三层之间的线不是直的。我需要在代码中做哪些更改才能使它变直? 在此处输入图片描述

\documentclass[
    12pt, % font size
    a4paper, % paper format
    oneside, % one-sided pages
]{article}

\usepackage{xcolor}
\usepackage{tikz} % draw figures
\usetikzlibrary{positioning, shadings}
\usetikzlibrary{arrows}

\colorlet{punct}{red!60!black}
\definecolor{delim}{RGB}{20,105,176}

\begin{document}

\begin{tikzpicture}[auto, node distance = 0.6cm, thick,
every node/.style = {rectangle, font=\sffamily\normalsize , white,
    top color = punct, bottom color = punct,
    text width = 3cm, align = center, minimum height = 2.4cm}]
% First Level
\node (Projektleiter) {\textbf{Projektleiter}\\Severin};
\coordinate [below = 2cm of Projektleiter] (second);
% Second Level
\node (Stv-Projektleiter) [left  = 2mm of second]  {\textbf{Stv. Projektleiter}\\Pascal};
\coordinate [below = 1cm of Stv-Projektleiter] (third);
% Third Level
\node (Informatik) [below = of third] {\textbf{Leiter Informatik}\\Jonas};
\node (Elektrotechnik) [left = of Informatik] {\textbf{Leiter Elektrotechnik}\\Manuel};
\node (Maschinenbau) [right = of Informatik] {\textbf{Leiter Maschinenbau}\\Roman};
\node (Redaktion) [right = of Maschinenbau] {\textbf{Redaktorin}\\Sindi};
\coordinate [below = 1cm of Informatik] (fourth);
% Fourth Level
\node (Stv-Maschinenbau) [below = of Maschinenbau] {\textbf{Stv. Maschinenbau}\\Valentin};
\draw [delim,thick]
(Projektleiter) -- (second) -- (Stv-Projektleiter)
(Projektleiter) -- (second) -- (third) -| (Informatik)
(third) -| (Elektrotechnik)
(third) -| (Maschinenbau)
(third) -| (Redaktion)
(Maschinenbau) -- (Stv-Maschinenbau);
\end{tikzpicture}

\end{document}

答案1

事实证明,在第四层不应该(Projektleiter) -- (second) -- (third) -| (Informatik)(Projektleiter) -- (second) |- (third) -- (Informatik)

\documentclass[
12pt, % font size
a4paper, % paper format
oneside, % one-sided pages
]{article}

\usepackage{xcolor}
\usepackage{tikz} % draw figures
\usetikzlibrary{positioning, shadings}
\usetikzlibrary{arrows}

\colorlet{punct}{red!60!black}
\definecolor{delim}{RGB}{20,105,176}

\begin{document}

\begin{tikzpicture}[
auto, node distance=0.6cm,thick,
every node/.style={rectangle,font=\sffamily\normalsize,white, top color=punct,bottom color=punct,text width=3cm, align=center,minimum height=2.4cm}]
% First Level
\node (Projektleiter) {\textbf{Projektleiter}\\Severin};
\coordinate [below = 2cm of Projektleiter] (second);
% Second Level
\node (Stv-Projektleiter) [left=2mm of second]  {\textbf{Stv. Projektleiter}\\Pascal};
\coordinate [below = 1cm of Stv-Projektleiter] (third);
% Third Level
\node (Informatik) [below = of third] {\textbf{Leiter Informatik}\\Jonas};
\node (Elektrotechnik) [left = of Informatik] {\textbf{Leiter Elektrotechnik}\\Manuel};
\node (Maschinenbau) [right = of Informatik] {\textbf{Leiter Maschinenbau}\\Roman};
\node (Redaktion) [right = of Maschinenbau] {\textbf{Redaktorin}\\Sindi};
\coordinate [below = 1cm of Informatik] (fourth);
% Fourth Level
\node (Stv-Maschinenbau) [below = of Maschinenbau] {\textbf{Stv. Maschinenbau}\\Valentin};
\draw [delim,thick]
(Projektleiter) -- (second) -- (Stv-Projektleiter)
(Projektleiter) -- (second) |- (third) -- (Informatik)
(third) -| (Elektrotechnik)
(third) -| (Maschinenbau)
(third) -| (Redaktion)
(Maschinenbau) -- (Stv-Maschinenbau);
\end{tikzpicture}

\end{document}

答案2

一种(非常)不同的绘制方式。通过使用treesTikZ 库,这非常简单,代码也非常简洁:

\documentclass[12pt, tikz, 
               border=3mm, many
              ]{standalone}
\usetikzlibrary{positioning, shadings, trees}
\usetikzlibrary{arrows}

\colorlet{punct}{red!60!black}
\definecolor{delim}{RGB}{20,105,176}

\begin{document}
    \begin{tikzpicture}[%auto, thick,
          node distance = 3mm,
      every node/.style = {rectangle, fill=punct, font=\sffamily, text=white,
                           text width = 3cm, minimum height = 2.2cm,
                           align = flush center},
edge from parent/.style = {draw=delim, thick},
         level distance = 32mm,
       sibling distance = 34mm,
edge from parent fork down
                     ]
% First Level
\node (Projektleiter) {\textbf{Projektleiter}\\Severin}
% Second Level (only for coordinate)
    child{ node[coordinate] (second) {}
% Third Level
        child{ node {\textbf{Leiter Informatik}\\Jonas}}
        child{ node {\textbf{Leiter Elektrotechnik}\\Manuel}}
        child{ node {\textbf{Leiter Maschinenbau}\\Roman}
% Fourth Level
            child{ node {\textbf{Stv. Maschinenbau}\\Valentin}}}
% Third Level
        child{ node {\textbf{Redaktorin}\\Sindi}}
        };
% Second Level
\node [left=of second] (Stv-Projektleiter) {\textbf{Stv. Projektleiter}\\Pascal};
\draw [delim,thick] (Stv-Projektleiter) -- (second);
\end{tikzpicture}
    \end{document}

更简洁的代码可以通过forest封装获得,但我还没掌握。

如下图所示,我稍微修改了节点,对于填充我刚才使用了fill=punctnormalsize对于字体的定义是多余的,并且minimum height=22mm(符合我的口味)足够了......

在此处输入图片描述

相关内容