tikztree 边缘从父级分叉到孙级看起来不太好

tikztree 边缘从父级分叉到孙级看起来不太好

我想创建一个函数结构。我使用 pdflatex 和 texmaker,我也尝试使用 miktex。我的问题如下。从 function0 到 function4 的行有点奇怪,因为它跳过了一个级别: 在此处输入图片描述

代码:

\documentclass{scrreprt}
\usepackage{tikz}
\usepackage{tikz-qtree}
\usetikzlibrary{trees} % this is to allow the fork right path

\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\tikzset{grow'=right,level distance=25mm}
\tikzset{edge from parent/.style={draw,edge from parent fork right}}
\begin{scope}
\Tree
        [.function0
            [.mainfunction
            function1
            function2
            function3
            ]
            [\node{function4};]
        ]
\end{scope}
\end{tikzpicture}
\end{figure}
\end{document

我希望函数 4 与函数 1、函数 2 和函数 3 处于同一级别。有人知道我该如何更改底部的线条,使线条笔直吗?

提前感谢你的帮助 Nelson

PS:这个 MWE 是更大结构的一部分:

\documentclass[tikz]{standalone}
\begin{document}
\begin{figure}[!ht, width=\columnwidth]
{\scriptsize
\centering
\begin{tikzpicture}
\tikzset{grow'=right,level distance=25mm}
\tikzset{execute at begin node=\strut}
\tikzset{every tree node/.style={draw, rounded corners, anchor=base west,
         minimum width=20mm,text width=18mm,align=center}}
\tikzset{edge from parent/.style={draw,edge from parent fork right}}
\begin{scope}[frontier/.style={distance from root=75mm}]
\Tree
[.\makecell{Eisadhäsion\\ darstellen}
        [.\makecell{Oberflächen-\\ herstellung}
            [.\makecell{homogene\\ Oberfläche\\ herstellen}
            \node(f1){\makecell{Geometrie-\\ herstellung}};
            \node(f2){\makecell{Oberflächen-\\ behandlung}};
            \node(f3){\makecell{Oberflächen-\\ konditionierung}};
            ]
            [\node(f4){\makecell{Kontaktflächen-\\ definierung}};]
        ]
        [.\makecell{Kontaktflächen-\\vereisung}
            [.\makecell{homogene\\ Wolken-\\ herstellung}
                \node(f5){\makecell{Wind-\\ erzeugung}};
                \node(f6){\makecell{Wasserdruck-\\ erzeugung}};
                \node(f7){\makecell{Wasser-\\ eindüsung}};
            ]
            [\node(f8){\makecell{Kontaktflächen-\\ beströmung}};]
        ]
        [.\makecell{Kontaktflächen-\\enteisung}
            [.\makecell{Grenzschicht-\\ belastung}
                \node(f9){\makecell{Kraft-\\ erzeugung}};
                \node(f10){\makecell{Kraft-\\ übertragung}};
                \node(f11){\makecell{Kraft-\\ messung}};
            ]
        ]
        [\node(f12){\makecell{Festigkeits-\\ berechnung}};]
]
\end{scope}

\tikzset{grow'=left,level distance=25mm, sibling distance =3.8mm}
\tikzset{execute at begin node=\strut}
\tikzset{every tree node/.style={draw, rounded corners, anchor=base west,
         minimum width=20mm,text width=18mm,align=center}}
\tikzset{edge from parent/.style={draw, edge from parent fork left}}
\begin{scope}[frontier/.style={distance from root=75mm}, xshift=190mm, yshift=4.9mm]
\Tree
[.\makecell{Torsions-\\ messverfahren}
        [\node(p12){\makecell{Modell-\\ rechnung}};]
        [.\makecell{Torsions-\\ prüfstand}
            [.\makecell{Drehmoment-\\ erzeugung}
                \node(p11){\makecell{Sensor-\\ system}};
                \node(p4){\makecell{Prüfkopf}};
                \node(p10){\makecell{Innen-/\\ Außenwelle}};
                \node(p13){\makecell{Gehäuse}};
                \node(p9){\makecell{Stellmotor}};
            ]
        ]
        [.\makecell{Eislabor mit\\ integr.\\ Windkanal-\\ system}
            [.\makecell{Windkanal-\\ system}
                \node(p7){\makecell{Spraybar}};
                \node(p6){\makecell{Pumpen-\\ system}};
                \node(p5){\makecell{Windkanal}};
            ]
        ]
        [.\makecell{Lacksystem}
            [.\makecell{homogene\\ Oberfläche\\ herstellen}
                \node(p3){\makecell{Lagerung}};
                \node(p2){\makecell{Lackierung}};
                \node(p1){\makecell{Zylinder}};
            ]
        ]
]
\end{scope}

\begin{scope}[dashed]
\tikzstyle{arrow} = [thick,>=stealth]
 \draw [arrow] (f1.east)--(p1.west);
 \draw [arrow] (f2.east)--(p2.west);
 \draw [arrow] (f3.east)--(p3.west);
 \draw [arrow] (f4.east)--(p4.west);
 \draw [arrow] (f5.east)--(p5.west);
 \draw [arrow] (f6.east)--(p6.west);
 \draw [arrow] (f7.east)--(p7.west);
 \draw [arrow] (f7.east)--(p6.west);
 \draw [arrow] (f8.east)--(p4.west);
 \draw [arrow] (f8.east)--(p5.west);
 \draw [arrow] (f9.east)--(p9.west);
 \draw [arrow] (f10.east)--(p10.west);
 \draw [arrow] (f10.east)--(p1.west);
 \draw [arrow] (f10.east)--(p13.west);
 \draw [arrow] (f10.east)--(p11.west);
 \draw [arrow] (f11.east)--(p11.west);
 \draw [arrow] (f12.east)--(p12.west);
\end{scope}
\begin{scope}
\node at (5,7.5) [rounded corners] {{\normalsize \texbf{Funktionsstruktur}}};
\node at (16,7.5) [rounded corners] {{\normalsize \texbf{Produktstruktur}}};
\end{scope}
\end{tikzpicture}
}
\end{figure}
\end{document}

它看起来像这样: 在此处输入图片描述

所以:

  • 2 棵树(树头相反)
  • 它们之间的可变连接(虚线)
  • 2 个标题

答案1

在此处输入图片描述

\documentclass[tikz]{standalone}
\usepackage{forest}

\begin{document}
    \begin{forest}
        for tree={
            edge path={
                \noexpand\path[\forestoption{edge}](!u.parent anchor) -- +(5pt,0) |- (.child anchor)\forestoption{edge label};},
            grow=0,
            reversed, % tree direction
            parent anchor=east,
            child anchor=west, % edge anchors
            anchor=west,
            if n children=0{tier=word}{}
        }
        [function0
        [mainfunction
        [function1]
        [function2]
        [function3]
        ]
        [function4]
        ]
    \end{forest}
\end{document}

答案2

经过一些经验,答案很简单:我只需要从 function4 中删除括号 []。我还添加了“与根的距离”选项,将 function4 放在与 function1 相同的级别。因此解决方案如下:

\documentclass{scrreprt}
\usepackage{tikz}
\usepackage{tikz-qtree}
\usetikzlibrary{trees} % this is to allow the fork right path

\begin{document}
\begin{figure}
{\scriptsize
\centering
\begin{tikzpicture}
\tikzset{grow'=right,level distance=25mm, sibling distance=5mm}
\tikzset{edge from parent/.style={draw,edge from parent fork right}}
\begin{scope}[frontier/.style={distance from root=50mm}] %added distance from root to bring function4 on the same level as function1
\Tree
        [.function0
            [.mainfunction
            function1
            function2
            function3
            ]
            \node{function4};   % Delete the brackets [] here
        ]
\end{scope}
\end{tikzpicture}
}
\end{figure}
\end{document}

输出: 在此处输入图片描述

相关内容