6

My figure now looks like figure 1 using below code figure 1 whenever I try to add more blocks ,the blocks become overlapping .

% https://www.packtpub.com/hardware-and-creative/latex-cookbook
\documentclass[border=4pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[sibling distance=10em,
  every node/.style = {shape=rectangle, rectangle,
    draw, align=center,
    top color=white, bottom color=blue!20}]]
  \node {Indoor Localization System}
    child { node {Proximity} 
           child { node {aoa1} }
       child { node {aoa2} }}
        child { node {Angulation} }
    child { node {Lateration}
      child { node {Signal Strength}
        child { node {aoa} }
        child { node {aoa1} }
        child { node {aoa2} } }
      child { node {Time of flight}}};
\end{tikzpicture}
\end{document}

But I want my figure to look like this figure 2. Kindly how I should change my code to do this. Forget about the text but the boxes.Thanks

enter image description here

  • If you have a clear idea about where the nodes should be put at, you can simply put the nodes by hand – Symbol 1 Dec 8 '15 at 17:23
  • @Symbol1 I dont know how to add nodes below first node.Cam you help me how to add three nodes below the first node. Please – Haider Dec 8 '15 at 17:25
  • 1
    \node at(4,5){text}; and so on. This is the simplest way to get full control of node position. – Symbol 1 Dec 8 '15 at 17:29
  • 1
    That code actually produces a lot of errors and no output at all as is. – Torbjørn T. Dec 8 '15 at 19:53
  • @Symbol1 Can you have look please – Haider Dec 9 '15 at 12:39
4

Root and branch

I'm not a dendrologist, so trees are not something I use a lot. The following shows one way of modifying the layout of a tree by changing the sibling distance for individual children. I don't know if this is exactly how you'd like it, but you can use it as a starting point.

enter image description here

\documentclass[border=4mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{trees}
\begin{document}
\begin{tikzpicture}[sibling distance=2cm,level distance=2cm,
  box/.style={
       shape=rectangle,
       font=\small,
       draw,
       align=center,
       minimum height=1.5cm,
       text width=1.5cm,
       top color=white,
       bottom color=blue!20}
]
\node  [box,text width=3cm] {Indoor\\Localization\\System} [edge from parent fork down]
  child { node [box] {Proximity} 
       child { node [box] {aoa1} }
       child { node [box] {aoa2} }}
  child { node [box] {Angulation} }
  child [sibling distance=3cm] { node [box] (lat) {Lateration}
        child [sibling distance=4cm]  { node [box] {Signal Strength}
             child [sibling distance=2cm] { node [box] {aoa} }
             child [sibling distance=2cm] { node [box] {aoa1} }
             child [sibling distance=2cm] { node [box] (aoa2) {aoa2} } }
        child [sibling distance=0cm]{ node [box] (tof) {Time of flight}}};

\draw [latex-] (tof.east) ++(0.3cm,0) coordinate (arrowend) -- ++(1cm,0) node[right] {Some text};
\draw [latex-] (arrowend|- lat.east) -- ++(1cm,0) node[right] {Some other text};
\draw [latex-] (arrowend |- aoa2.east)--  ++(1cm,0) node[right] {Some third text};
\end{tikzpicture}
\end{document}

Manual positioning

As Symbol1 mentioned in a comment, you could also position all the nodes manually. In the following code I've not used explicit coordinates as he suggested, but placed all nodes relative to other nodes. Here I've more or less reproduced the layout in the image you showed. It can be made a bit more compact my modifying some distances here and there.

enter image description here

\documentclass[border=4mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[
  box/.style={
       shape=rectangle,
       font=\small,
       draw,
       align=center,
       minimum height=1.5cm,
       minimum width=1.5cm,
       top color=white,
       bottom color=blue!20},
node distance=1cm and 0.5cm]

% root node
\node (loc) [box] {Location\\system};

% first row
\node (proc) [box,below=of loc] {Proximity};
\node (ang) [box,right=of proc] {Angulation};
\node (lat) [box,left=1cm of proc] {Lateration};

% right tree
\node (recang) [box,below=of ang] {Recieved\\angle};
\node (aoa) [box,below=of recang] {AOA};
\node (aa) [box,below=of aoa] {Antenna\\array};

% left tree
\node (ss) [box,below left=1cm and -0.5cm of lat] {Signal\\strength};
\node (rss) [box,below=of ss] {RSS};
\node (rft) [box,below=of rss] {RF\\Tranceiver};

\node (pt) [box,below right=1cm and 0cm of lat] {Propagation\\time};
\node (tdoa) [box,below left=1cm and -0.8cm of pt] {TDOA};
\node (toa) [box,below right=1cm and -0.8cm of pt] {TOA};
\node (and) [box,below=of tdoa,font=\scriptsize] {Ultrasonic\\Transducer\\and RF\\Transceiver};
\node (or) [box,below=of toa,font=\scriptsize] {Ultrasonic\\Transducer\\or RF\\Transceiver};

% annotations on right
\foreach \start/\txt in {ang/Positioning, recang/Variable, aoa/Ranging, aa/Device}
   \draw [latex-] (\start.east) ++(0.3cm,0) -- ++(1cm,0) node[right]{\txt};

% draw connections
\draw (loc) --coordinate (i1) (proc);
\draw (i1) -| (lat);
\draw (i1) -| (ang) -- (recang) -- (aoa) -- (aa);

\path (lat.south) ++(0,-0.5cm) coordinate (i2);
\path (pt.south) ++(0,-0.5cm) coordinate (i3);

\draw (lat) -- (i2) -| (ss) -- (rss) -- (rft);
\draw (i2) -| (pt) -- (i3) -| (tdoa) -- (and);
\draw (i3) -| (toa) -- (or);
\end{tikzpicture}
\end{document}
| improve this answer | |
  • Thank you so much for your comment.Yes this is exactly I wanted to draw.Thanks for the time! – Haider Dec 10 '15 at 9:10
4

Something like this?

tree

\documentclass[border=10pt,tikz,multi]{standalone}
\usepackage{forest}
\begin{document}
\begin{forest}
  for tree={
    edge path={
      \noexpand\path [\forestoption{edge}] (!u.parent anchor) -- +(0,-5pt) -| (.child anchor);
    },
    draw,
    align=center,
    top color=white,
    bottom color=blue!20,
    parent anchor=south,
    child anchor=north,
    if={isodd(n_children)}{%
      for children={
        if={equal(n,(n_children("!u")+1)/2)}{calign with current}{}
      },
    }{}
  }
  [Indoor Localization System
    [Lateration
      [Signal\\Strength
        [aoa]
        [aoa1]
        [aoa2]
      ]
      [Time\\of flight
      ]
    ]
    [Proximity
      [aoa1]
      [aoa2]
    ]
    [Angulation
    ]
  ]
\end{forest}
\end{document}

EDIT

If you are feeling adventurous, you could try justtrees, an experimental package which is, basically, a wrapper for forest. It is intended to make it easy to add horizontal labels and align them with the various levels of the tree in a vertical stack at the left or the right or both. In this case, you'd want the stack on the right, which is the default.

We can adapt the style slightly in order to draw the arrows automatically along with the creation of the vertical stack of labels.

The result looks like this:

justtrees label stack

To use the following code, you need version 0.05 of the package. Please let me know if you want a copy. It is experimental so (1) I would be glad if others would test it, but (2) it certainly has bugs!

\documentclass[border=10pt,tikz,multi]{standalone}
\usepackage{justtrees}% version 0.05
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{justtree}{%
  for tree={
    edge path={
      \noexpand\path [\forestoption{edge}] (!u.parent anchor) -- +(0,-5pt) -| (.child anchor);
    },
    draw,
    align=center,
    top color=white,
    bottom color=blue!20,
    parent anchor=south,
    child anchor=north,
    if={isodd(n_children)}{%
      for children={
        if={equal(n,(n_children("!u")+1)/2)}{calign with current}{}
      },
    }{},
    font=\sffamily,
  },
  just format={font=\sffamily, xshift=10mm},
  right just/.append style={
    tikz+/.wrap pgfmath arg={
      \draw [-{Stealth[]}, thick, shorten >=5pt] (right just ##1.west) -- (right just ##1.west -| just tree east);
    }{level()}
  },
}
  [Indoor Localization System
    [Lateration, just=Positioning
      [Signal\\Strength, just=Variable
        [aoa, just=Ranging]
        [aoa1
          [Another\\thing]
        ]
        [aoa2]
      ]
      [Time\\of flight
      ]
    ]
    [Proximity
      [aoa1
        [something\\else
          [Further\\stuff, just=Device]
        ]
      ]
      [aoa2]
    ]
    [Angulation
    ]
  ]
\end{justtree}
\end{document}
| improve this answer | |
  • Thank you so much all,Yes I need the copy where I can find it. – Haider Dec 10 '15 at 9:08
  • @Haider Can you find it in chat.stackexchange.com/rooms/32793/justtrees-v-0-05 ? I've never tried to create a chat room from scratch before, so let me know if not as I might have done it wrongly. – cfr Dec 10 '15 at 12:05
  • When the new version of forest is released, I plan to update and hopefully put this on CTAN, so do report the bugs! – cfr Dec 10 '15 at 12:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.