如何将边发送回 tikz 树中

如何将边发送回 tikz 树中

我正在使用 tikz 树来创建下图:

\begin{tikzpicture}
  [
    sibling distance        = 2em,
    level distance          = 8em,
    edge from parent/.style = {draw, -latex},
    every node/.style       = {font=\footnotesize},
    treenode/.style = {shape=rectangle, rounded corners, draw, align=center,fill=white},
    dummy/.style    = {circle,draw},
    sloped
  ]
  \node [treenode] {\textbf{Where do I have to}\\\textbf{extract data from?}}
        child[grow=right] { node [dummy] {} 
            child{ node [treenode] {Industrial control systems devices \cite{myers2018anomaly}} edge from parent}
            child{ node [treenode] {Ubiquitous computing devices \cite{yousfi2019discovering}} edge from parent}
            child{ node [treenode] {Geotags \cite{diamantini2017discovering}} edge from parent}
            child{ node [treenode] {Eye tracking devices \cite{ioannou2020mining}} edge from parent}
            child{ node [treenode] {Ventricular assist devices \cite{movahedi2019sequential}} edge from parent}
            child{ node [treenode] {WiFi-base indoor positioning systems \cite{liu2014proactive} \cite{hwang2017process}} edge from parent}
        edge from parent node [above] {Hardware}}
        child[grow=left] { node [dummy] {} 
            child{ node [treenode] {Relational databases \cite{syamsiyah2020process} \cite{andrews2020quality}} edge from parent}
            child{ node [treenode] {Electronic data interchange messages \cite{engel2016analyzing} \cite{krathu2014framework}} edge from parent}
            child{ node [treenode] {Natural language texts \cite{metsker2018identification} \cite{kabicher2011human}} edge from parent}
            child{ node [treenode] {Electronic medical records \cite{metsker2017pattern} \cite{chen2019mining}} edge from parent}
            child{ node [treenode] {Educational platforms \cite{cerezo2020process}} edge from parent}
            child{ node [treenode] {Librarian systems \cite{kouzari2018process}} edge from parent}
            child{ node [treenode] {Software development projects \cite{samalikova2011toward}} edge from parent}
            child{ node [treenode] {Different information systems \cite{myers2018anomaly} \cite{schuh2020data}} edge from parent}
        edge from parent node [above] {Software}};
\end{tikzpicture}

在此处输入图片描述

我该怎么做才能让边缘画在节点后面而不是节点上方?

答案1

使用该forest包的替代解决方案。也许有人会喜欢它。

案例 A:节点有一行文本(如问题所示),因此纵向页面中的图像比页面宽度略宽。因此,此解决方案适用于横向页面:

\documentclass[margin=3.14159mm]{standalone}
\usepackage{forest}
\usetikzlibrary{arrows.meta}
\tikzset{lbl/.style = {inner sep=2pt, font=\footnotesize, midway, above}}

\begin{document}
    \begin{forest}
for tree = {
% node style
    rounded corners,
    draw,
    minimum size = 1em,
            font = \small,
% tree style
    edge = {-{Straight Barb[angle=60:2pt 3]}, semithick},
    edge path'={(!u.parent anchor) -- (.child anchor)},
    l sep=12mm,
    s sep=1mm
           }
% tree body code
[root,
    [ , circle, edge label={node[lbl] {Hard\-ware}},
        %%%%    settings for the right branch
        for tree={grow=east, anchor=west, child anchor=west},
        before computing xy={l=-3,s=+22mm},
        %%%%
        [Industrial control systems devices \cite{myers2018anomaly}]
        [Ubiquitous computing devices \cite{yousfi2019discovering}]
        [Geotags \cite{diamantini2017discovering}]
        [Eye tracking devices \cite{ioannou2020mining}]
        [Ventricular assist devices \cite{movahedi2019sequential}]
        [WiFi-base indoor positioning systems \cite{liu2014proactive, hwang2017process}]
    ]
    [ , circle, edge label={node[lbl] {Soft\-ware}},
        %%%%    settings for the left branch
        for tree={grow=west, anchor=east, child anchor=east},
        before computing xy={l=-3,s=-22mm},
        %%%%
        [Relational databases \cite{syamsiyah2020process} \cite{andrews2020quality}]
        [Electronic data interchange messages \cite{engel2016analyzing} \cite{krathu2014framework}]
        [Natural language texts \cite{metsker2018identification} \cite{kabicher2011human}]
        [Electronic medical records \cite{metsker2017pattern} \cite{chen2019mining}]
        [Educational platforms \cite{cerezo2020process}]
        [Librarian systems \cite{kouzari2018process}]
        [Software development projects \cite{samalikova2011toward}]
        [Different information systems \cite{myers2018anomaly} \cite{schuh2020data}]
    ]
]
\end{forest}
\end{document}

在此处输入图片描述

案例 B:节点具有规定的文本宽度,因此节点中的文本被分成更多行。这样,可以调整图像使其比文本宽度更窄,因此可以在纵向页面上显示。

\documentclass[margin=3mm]{standalone}
\usepackage{forest}
\usetikzlibrary{arrows.meta}
\tikzset{lbl/.style = {inner sep=2pt, font=\footnotesize, midway, above}}

\begin{document}
    \begin{forest}
for tree = {
% node style
    rounded corners,
    draw,
    minimum size = 1em,
% prescribed nodes width and font size
        if level = 1{}{if level = 0{}{text width = 10em, /tikz/align=flush center}}{},
            font = \linespread{0.84}\selectfont,
% tree style
    edge = {-{Straight Barb[angle=60:2pt 3]}, semithick},
    edge path'={(!u.parent anchor) -- (.child anchor)},
    l sep=12mm,
    s sep=1mm
           }
% tree body code:
%  code for tree is the same as is in the above example
\end{forest}
\end{document}

在此处输入图片描述

答案2

使用这个答案,进一步指这个,您可以告诉 TikZ 将某些东西放置在特定图层上。在这里,您可以将其添加到您的edge from parent/.style定义中,以将边缘放置在名为的背景图层上bg

在此处输入图片描述

代码:

\documentclass[tikz,border=2pt]{standalone}
\pgfdeclarelayer{bg}
\pgfsetlayers{bg,main}
%%% see https://tex.stackexchange.com/a/20426
\makeatletter
\pgfkeys{%
  /tikz/on layer/.code={
    \pgfonlayer{#1}\begingroup
    \aftergroup\endpgfonlayer
    \aftergroup\endgroup
  }
}
\def\node@on@layer{\aftergroup\node@@on@layer}
\makeatother
%%%
\begin{document}
\begin{tikzpicture}
  [
    sibling distance        = 2em,
    level distance          = 9em,
    edge from parent/.style = {draw, -latex, on layer=bg},
    every node/.style       = {font=\footnotesize},
    treenode/.style = {shape=rectangle, rounded corners, draw, align=center,fill=white},
    dummy/.style    = {circle,draw},
    sloped
  ]
  \node [treenode] {\textbf{Where do I have to}\\\textbf{extract data from?}}
        child[grow=right] { node [dummy] {} 
            child{ node [treenode] {Industrial control systems devices \cite{myers2018anomaly}} edge from parent}
            child{ node [treenode] {Ubiquitous computing devices \cite{yousfi2019discovering}} edge from parent}
            child{ node [treenode] {Geotags \cite{diamantini2017discovering}} edge from parent}
            child{ node [treenode] {Eye tracking devices \cite{ioannou2020mining}} edge from parent}
            child{ node [treenode] {Ventricular assist devices \cite{movahedi2019sequential}} edge from parent}
            child{ node [treenode] {WiFi-base indoor positioning systems \cite{liu2014proactive} \cite{hwang2017process}} edge from parent}
        edge from parent node [above] {Hardware}}
        child[grow=left] { node [dummy] {} 
            child{ node [treenode] {Relational databases \cite{syamsiyah2020process} \cite{andrews2020quality}} edge from parent}
            child{ node [treenode] {Electronic data interchange messages \cite{engel2016analyzing} \cite{krathu2014framework}} edge from parent}
            child{ node [treenode] {Natural language texts \cite{metsker2018identification} \cite{kabicher2011human}} edge from parent}
            child{ node [treenode] {Electronic medical records \cite{metsker2017pattern} \cite{chen2019mining}} edge from parent}
            child{ node [treenode] {Educational platforms \cite{cerezo2020process}} edge from parent}
            child{ node [treenode] {Librarian systems \cite{kouzari2018process}} edge from parent}
            child{ node [treenode] {Software development projects \cite{samalikova2011toward}} edge from parent}
            child{ node [treenode] {Different information systems \cite{myers2018anomaly} \cite{schuh2020data}} edge from parent}
        edge from parent node [above] {Software}};
\end{tikzpicture}
\end{document}

相关内容