-3

enter image description hereI would like to reproduce this figure properly in Latex. I have several imported figures (.eps but I guess it does not really matter) and I want to draw arrows (instead of lines) between some of them (as on the figure). The arrows could potentially be of any direction (not necessarily vertical nor horizontal). Ideally, the arrows would hold even if I change the size/position of the figures. What is the most practical way to do that ? Could someone provide me a minimal working example ? I really have no idea on how to start

1 Answers1

5

Let's divide the problem into two parts:

  1. Placing nodes and connect them (without forest or other package)
  2. Inserting imagens inside a node

and to keep things neat and tidy, let's also create some styles, so we don't need to repeat ourselves over and over.

The style figNode is responsable for inserting a picture at the center of the node. Moreover, style mySimpleArrow define arrows and style myBlock define the minimum sizes of our nodes, both have a default setting, so you may define how the style with behave globally or define locally inside a specific node through mySimpleArrow={yellow}{red}.

The first \begin{scope} block places all of our nodes, the second defines the paths between nodes.

I present two figures. First figure has labels and nodes are displaced right=<distance> of <node>. It solves our first problem. Now, to solve the second, we just add our figNode style. Unfortunately, the right=... syntax interferes with figNode, so I created a second figure where nodes are placed with at (x,y) coordinates.

Finally, to achieve your results, just replace the contents inside \includegraphics with your figures.

\documentclass{article}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{pgfplots}
\usetikzlibrary{positioning}
\tikzset{figNode/.style={
    path picture={
      \node at (path picture bounding box.center) {#1};}}
}
\tikzset{mySimpleArrow/.style n args={2}{
    >={latex[#1]},
    every path/.style={draw=#2}
  },
  mySimpleArrow/.default={black}{black}
}
\tikzset{myBlock/.style n args={2}{
    every node/.style={rectangle,draw, text=black,
      minimum width=#1, minimum height=#2,}
  },
  myBlock/.default={1cm}{1cm}
}
\begin{document}
\begin{tikzpicture}[very thick]
  \begin{scope}[shift={(3.0,-0.5)},myBlock]
    \node [label=above:Road] (A) at (-6,6) {$A$};
    \node[right=0.5 of A] (B) [label=above:Metal]{$B$};
    \node[right=0.5 of B] (C) [label=above:Dirt]{$C$};
    \node[right=0.5 of C] (D) [label=above:Roof]{$D$};
    \node[right=0.5 of D] (E) [label=above:Grass 1]{$E$};
    \node[right=0.5 of E] (F) [label=above:Grass 2]{$F$};
    \node[right=0.5 of F] (G) [label=above:Trees]{$G$};
\node (H) at (-5,3.5) [label=below left:Road + Metal]{$H$};

\node (I) at (-3.5,2) [label=below left:Road + Metal + Dirt]{$I$};
\node[right=3 of I] (J) [label=below:Grass]{$J$};

\node (K) at (-2,0.5) [label=below:Non-vegetation]{$K$};
\node[right=3 of K] (L) [label=below:Vegetation]{$L$};

\end{scope}

\begin{scope}[mySimpleArrow] \path[->] (K) -- (I); \path[->] (K) -- (D); \path[->] (I) -- (H); \path[->] (I) -- (C); \path[->] (H) -- (A); \path[->] (H) -- (B);

\path[-&gt;] (L) -- (J);
\path[-&gt;] (L) -- (G);
\path[-&gt;] (J) -- (E);
\path[-&gt;] (J) -- (F);

\end{scope} \end{tikzpicture} \begin{tikzpicture}[very thick] \begin{scope}[shift={(3.0,-0.5)},myBlock] % \draw [figNode={\includegraphics{example-image-a}},label=above:Road] coordinate(A) (-6,6) rectangle ++(1,1); \node [label=above:Road,figNode={\includegraphics[width=1cm]{example-image-a}}] (A) at (-6,6) {}; \nodefigNode={\includegraphics[width=1cm]{example-image-b}} at (-4.5,6) [label=above:Metal]{}; \node[figNode={\includegraphics[width=1cm]{example-image-c}}] (C) at (-3,6) [label=above:Dirt]{}; \node[figNode={\includegraphics[width=1cm]{example-image-duck}}] (D) at (-1.5,6) [label=above:Roof]{}; \node[figNode={\includegraphics[width=1cm]{example-image-1x1}}] (E) at (0,6) [label=above:Grass 1]{}; \node[figNode={\includegraphics[width=1cm]{example-image-a}}] (F) at (1.5,6) [label=above:Grass 2]{}; \node[figNode={\includegraphics[width=1cm]{example-image-b}}] (G) at (3,6) [label=above:Trees]{};

\node[figNode={\includegraphics[width=1cm]{example-image-c}}] (H) at (-5,3.5) [label=below left:Road + Metal]{};

\node[figNode={\includegraphics[width=1cm]{example-image-duck}}] (I) at (-3.5,2) [label=below left:Road + Metal + Dirt]{};
\node[figNode={\includegraphics[width=1cm]{example-image-1x1}}] (J) at (0.5,2) [label=below:Grass]{};

\node[figNode={\includegraphics[width=1cm]{example-image-a}}] (K) at (-2,0.5) [label=below:Non-vegetation]{};
\node[figNode={\includegraphics[width=1cm]{example-image-b}}] (L) at (2,0.5) [label=below:Vegetation]{};

\end{scope}

\begin{scope}[mySimpleArrow] \path[->] (K) -- (I); \path[->] (K) -- (D); \path[->] (I) -- (H); \path[->] (I) -- (C); \path[->] (H) -- (A); \path[->] (H) -- (B);

\path[-&gt;] (L) -- (J);
\path[-&gt;] (L) -- (G);
\path[-&gt;] (J) -- (E);
\path[-&gt;] (J) -- (F);

\end{scope} \end{tikzpicture} \end{document}

First figure with letter-labeled nodes.

enter image description here

Second figure with figure inside nodes.

enter image description here

FHZ
  • 3,939