TransWikia.com

How to send edges to back in tikz trees

TeX - LaTeX Asked by Luiz Fernando Puttow Southier on April 2, 2021

I’m using tikz trees to create the following diagram:

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}

enter image description here

What can I do so that the edges are draw behind the nodes and not over them?

2 Answers

Alternative solutions with use of the forest package. Maybe someone will like it.

Case A: nodes have one line text (as shown in question), consequently image in portrait oriented page is a wee bit wider than page width. Therefore this solution is appropriate for landscape page:

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}

enter image description here

Case B: nodes have prescribed text width, consequently text in nodes is broken into more lines. With this the image can be adjust that is narrower than text width and therefore can be presented on portrait oriented page.

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}

enter image description here

Correct answer by Zarko on April 2, 2021

Using this answer, which further refers to this one, you can tell TikZ to place something on a specific layer. Here you can add this to your edge from parent/.style definition to place the edges on a background layer called bg.

enter image description here

Code:

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
    aftergroupendpgfonlayer
    aftergroupendgroup
  }
}
defnode@on@layer{aftergroupnode@@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}

Answered by erik on April 2, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP