How can I draw this graph with TikZ or forest?
the problem is indeed the connection between Distance, Kind and Pixel. Since "forest" is really a tree, they cant be connect with forest and we have to use the draw command. Therefore we name some nodes. Decorate as you like.
\documentclass[tikz,convert={size=640},multi]{standalone}
\usepackage{tikz}
\usepackage{forest}
\usetikzlibrary{graphs,positioning}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{arrows}
\begin{document}
\begin{forest}
for descendants={anchor=east, child anchor=east, grow=west},
grow=west, anchor=north, parent anchor=north
[Acceleration, rotate=90
[Map]
[Destination]
[Vector]
[Location]
[ [Kind {\tiny (street signs, cars, people)},name=Kind [Pixel, name=Pixel]]
[Distance, name= Distance]]]
\draw[->] (Kind) to[out=west,in=east] (Pixel);
\draw[->] (Distance) to[out=west,in=south east] (Pixel);
\end{forest}
\end{document}
It isn't entirely clear what you mean by 'structure'. Normally, for a graph or tree, I'd understand this to mean the way in which the nodes are connected to each other and not the distance and direction of one node relative to another. But it seems you mean the latter as well, although whether this is really it is another matter.
If so, I take it you want something like this:
This is not hard to do in forest
. It is just a bit fiddly:
\documentclass[tikz,border=10pt,multi]{standalone}
\usepackage{forest}
\forestset{
default preamble={
for tree={
grow=west,
parent anchor=children,
child anchor=parent,
anchor=east,
draw,
minimum height=4ex
}
}
}
\begin{document}
\begin{forest}
[Acceleration
[Map]
[Destination]
[Vector]
[Location]
[{Kind(Street signs, cars, people,...)}, name=kind, tikz+={%
\draw [\forestoption{edge}] (.parent anchor) -- (shape.child anchor);
}
]
[, phantom
[Shape, before computing xy={%
l+/.wrap pgfmath arg={#1}{width(content("kind"))},
}, name=shape
[Line
[Pixel]
]
]
]
[Distance, before drawing tree={%
x-/.wrap pgfmath arg={#1}{width(content("kind"))-width(content())}
}, edge path'={%
(!u.parent anchor) -- (kind.child anchor |- .child anchor) -- (.child anchor)
}, tikz+={%
\draw [\forestoption{edge}] (.parent anchor) -- (shape.child anchor);
}
]
]
\end{forest}
\end{document}
EDIT
I have no idea what 'vertical space' you ask in the comments to get rid of. The following code sacrifices structural replication for the sake of what may or may not be the desired appearance.
\documentclass[tikz,border=10pt,multi]{standalone}
\usepackage{forest}
\forestset{
default preamble={
for tree={
grow=west,
parent anchor=children,
child anchor=parent,
anchor=east,
draw,
minimum height=4ex
}
}
}
\begin{document}
\begin{forest}
[Acceleration
[Map]
[Destination]
[Vector]
[Location]
[{Kind(Street signs, cars, people,...)}, name=kind
[Shape, before computing xy={%
s/.wrap pgfmath arg={#1}{(-s("!u")+s("!un"))/2},
}, name=shape
[Line
[Pixel]
]
]
]
[Distance, before drawing tree={%
x-/.wrap pgfmath arg={#1}{width(content("kind"))-width(content())}
}, edge path'={%
(!u.parent anchor) -- (kind.child anchor |- .child anchor) -- (.child anchor)
}, tikz+={%
\draw [\forestoption{edge}] (.parent anchor) -- (shape.child anchor);
}
]
]
\end{forest}
\end{document}
If in your forest
version includes grow=west
inside for tree
options, the result is:
\documentclass[tikz,convert={size=640},multi]{standalone}
\usetikzlibrary{graphs,positioning}
\usepackage{forest}
\forestset{
default preamble={
for tree={
grow=west,
parent anchor=children,
child anchor=east,
anchor=east,
draw
}
}
}
\begin{document}
\begin{forest}
[Acceleration
[Map] [Destination] [Vector] [Location]
[{Kind(Street signs, cars, people,...)},name=kind]
[Distance,name=distance
[Shape [Line [Pixel]]]]]
\end{forest}
\end{document}
Update: Now with shape
and kind
manually connected
\documentclass[tikz,convert={size=640},multi]{standalone}
\usetikzlibrary{graphs,positioning}
\usepackage{forest}
\forestset{
default preamble={
for tree={
grow=west,
parent anchor=children,
child anchor=east,
anchor=east,
%draw
}
}
}
\begin{document}
\begin{forest}
[Acceleration
[Map] [Destination] [Vector] [Location]
[{Kind(Street signs, cars, people,...)},name=kind]
[Distance,name=distance
[Shape, name=shape [Line [Pixel]]]]]
\draw (shape.north)--++(90:1mm)-|([shift={(5mm,0mm)}]kind.south west);
\end{forest}
\end{document}