6

I was quite impressed by the solution given by "cfr" for the question posted here.

Can you suggest a method to change the two main children (labelled Projection matrix Theory and Reconstruction Algorithms) to position on the north and south of the root node (Compressed Sensing Theory)? That is, I would like the two main children nodes to open out towards north and south of the root node. The main child node "Reconstruction Algorithm" should appear just below the root node and the child node "Projection matrix Theory" should appear above the root node. The child nodes of "Projection matrix Theory" should open upward whereas the child nodes of "Reconstruction Algorithm" can remain intact.

I had made a comment on cfr's answer, requesting the same. As he suggested I am posting again it as a new question. Thanks.

EDIT: I tried to change it, but I landed up in getting this figure! enter image description here

The code I modified is given here:

     \documentclass[border=5pt]{standalone}
\usepackage{tikz,pgf}
\usepackage{forest}
\usetikzlibrary{arrows.meta, shapes.geometric, calc, shadows}

\colorlet{mygreen}{green!75!black}
\colorlet{col1in}{orange!30}
\colorlet{col1out}{orange!40}
%\colorlet{col1in}{red!30}
%\colorlet{col1out}{red!40}

\colorlet{col2in}{mygreen!40}
\colorlet{col2out}{mygreen!50}
\colorlet{col3in}{blue!30}
\colorlet{col3out}{blue!40}
\colorlet{col4in}{mygreen!20}
\colorlet{col4out}{mygreen!30}
\colorlet{col5in}{blue!10}
\colorlet{col5out}{blue!20}
\colorlet{col6in}{blue!20}
\colorlet{col6out}{blue!30}
\colorlet{col7out}{red!10}
\colorlet{col7in}{red!50}
\colorlet{col8out}{red!40}
\colorlet{col8in}{red!20}

%\colorlet{col7out}{orange}
%\colorlet{col7in}{orange!50}
%\colorlet{col8out}{orange!40}
%\colorlet{col8in}{orange!20}
\colorlet{linecol}{blue!60}

\begin{document}
\pgfkeys{/forest,
  rect/.append style={rectangle, rounded corners=2pt, inner color=col6in, outer color=col6out},
  ellip/.append style={ellipse, inner color=col5in, outer color=col5out},
  orect/.append style={rect, font=\sffamily\bfseries\LARGE, text width=325pt, text centered, minimum height=10pt, outer color=col7out, inner color=col7in},
  oellip/.append style={ellip, inner color=col8in, outer color=col8out, font=\sffamily\bfseries\large, text centered},
}
\begin{forest}
  for tree={
      font=\sffamily\bfseries,
      line width=1pt,
      draw=linecol,
      ellip,
      align=center,
      child anchor=north,
      parent anchor=south,
      drop shadow,
      l sep+=12.5pt,
      edge path={
        \noexpand\path[color=linecol, rounded corners=5pt, >={Stealth[length=10pt]}, line width=1pt, ->, \forestoption{edge}]
          (!u.parent anchor) -- +(0,-5pt) -|
          (.child anchor)\forestoption{edge label};
        },
      where level={3}{tier=tier3}{},
      where level={0}{l sep-=15pt}{},
      where level={1}{
        if n={1}{
          edge path={
            \noexpand\path[color=linecol, rounded corners=5pt, >={Stealth[length=10pt]}, line width=1pt, ->, \forestoption{edge}]
              (!u.north) -| (.child anchor)\forestoption{edge label};
            },
        }{
          edge path={
            \noexpand\path[color=linecol, rounded corners=5pt, >={Stealth[length=10pt]}, line width=1pt, ->, \forestoption{edge}]
              (!u.south) -| (.child anchor)\forestoption{edge label};
            },
        }
      }{},
  }
  [Compressed Sensing\\Theory, inner color=col1in, outer color=col1out, 
    [Projection Matrix\\Theory, inner color=col2in, grow'=north, outer color=col2out,
      [Optimise Projection\\Matrix, inner color=col4in, outer color=col4out, grow=south]
      [Reduce Number of\\Measurements, inner color=col4in, outer color=col4out,grow=south]
    ]
    [Reconstruction\\Algorithms, inner color=col3in, outer color=col3out
      [Convex Relaxation \\ Methods
        [Sparse Signal\\Estimate, rect, name=sse1
        ]
      ]
      [\hspace{1em} Greedy \hspace{1em} \\ Pursuits
        [Sparse Signal\\Estimate, rect, name=sse2
        ]
      ]
      [, phantom, calign with current
        [A\\B, phantom
          [Our Work, orect, name=us
            [{Improved Sparse Signal Estimate!}, oellip
            ]
          ]
        ]
      ]
      [Non-Convex\\ Methods
        [Sparse Signal\\Estimate, rect, name=sse3
        ]
      ]
      [Combinatorial\\Algorithms
        [Sparse Signal\\Estimate, rect, name=sse4
        ]
      ]
    ]
  ]
%  \begin{scope}[color=linecol, rounded corners=5pt, >={Stealth[length=10pt]}, line width=1pt, ->]
%    \draw (sse2.south) -- (us.north -| sse2.south);
%    \draw (sse3.south) -- (us.north -| sse3.south);
%    \coordinate (c1) at ($(sse1.south)!2/5!(sse2.south)$);
%    \coordinate (c2) at ($(sse3.south)!2/5!(sse4.south)$);
%    \draw (sse1.south) -- +(0,-10pt) -| (us.north -| c1);
%    \draw (sse4.south) -- +(0,-10pt) -| (us.north -| c2);
%  \end{scope}
\end{forest}
\end{document}

I was unable to place the node "Projection Matrix Theory" above the root node "Compressed Sensing". Similarly the arrows from the node "Projection Matrix Theory" are not ending at the intended place. Where am I going wrong?

6
  • 3
    You have a working code example, an idea of how you want to change the result, and the manual. Spend a few hours with those items. Then post your best attempt at getting what you want. Jul 16, 2014 at 13:57
  • I don't think this is simple to do with forest. Why not use the other solution offered to that question? Or, if you are drawing a mind map, use tikz's mindmap library?
    – cfr
    Jul 16, 2014 at 17:53
  • @cfr: I apologize for the old wrong title. I have edited it now. I tried the other solution offered. But I like your diagram more and hence wanted to modify that
    – Sooraj
    Jul 16, 2014 at 18:06
  • @Sooraj I just don't think forest is designed to do this. That isn't to say that there isn't some way of forcing it or some wizardry somebody will come along with. But it really, really doesn't want to let you do this. You can change the direction of growth for the subtree rooted in a node (see page 30), but that will not affect the direction of growth which affects that node itself. Effectively, you want 2 different directions of growth active for a single subtree and there is no obvious way of doing that.
    – cfr
    Jul 16, 2014 at 22:28
  • @Cfr: Exactly. I tried to play with all combinations, I was not able to grow children in two directions. Now I understand it clearly. Thanks!
    – Sooraj
    Jul 17, 2014 at 6:54

1 Answer 1

7

As I said in my comment, forest is not really designed (it seems to me) for this kind of diagram. At a given level within a given subtree, the direction of growth is, well, the direction of growth. You cannot specify one direction for one child and a different direction for another.

So to draw something of the kind I believe you want, you need to fake it. The trick here is to begin with an east-growing tree and a root with three children. We don't care about the root. It just allows the three nodes to be aligned vertically. The pseudo-root goes in the centre, the two subtree roots go above and below.

\documentclass[border=5pt]{standalone}

\usepackage{forest}
\usetikzlibrary{arrows.meta, shapes.geometric, calc, shadows}

\colorlet{mygreen}{green!75!black}
\colorlet{col1in}{red!30}
\colorlet{col1out}{red!40}
\colorlet{col2in}{mygreen!40}
\colorlet{col2out}{mygreen!50}
\colorlet{col3in}{blue!30}
\colorlet{col3out}{blue!40}
\colorlet{col4in}{mygreen!20}
\colorlet{col4out}{mygreen!30}
\colorlet{col5in}{blue!10}
\colorlet{col5out}{blue!20}
\colorlet{col6in}{blue!20}
\colorlet{col6out}{blue!30}
\colorlet{col7out}{orange}
\colorlet{col7in}{orange!50}
\colorlet{col8out}{orange!40}
\colorlet{col8in}{orange!20}
\colorlet{linecol}{blue!60}

\begin{document}
\pgfkeys{/forest,
  rect/.append style={rectangle, rounded corners=2pt, inner color=col6in, outer color=col6out},
  ellip/.append style={ellipse, inner color=col5in, outer color=col5out},
  orect/.append style={rect, font=\sffamily\bfseries\LARGE, text width=325pt, text centered, minimum height=10pt, outer color=col7out, inner color=col7in},
  oellip/.append style={ellip, inner color=col8in, outer color=col8out, font=\sffamily\bfseries\large, text centered},
}
\begin{forest}
  for tree={
      font=\sffamily\bfseries,
      line width=1pt,
      draw=linecol,
      ellip,
      align=center,
      drop shadow,
      l sep+=12.5pt,
      where level={0}{s sep+=15pt}{},
      grow'=east,
  }
  [,phantom
    [Projection Matrix\\Theory,
        inner color=col2in,
        outer color=col2out,
        for tree={
          grow=north,
          child anchor=south,
          parent anchor=north,
          edge path={
            \noexpand\path[color=linecol, rounded corners=5pt, >={Stealth[length=10pt]}, line width=1pt, ->, \forestoption{edge}]
              (!u.parent anchor) -- +(0,5pt) -|
              (.child anchor)\forestoption{edge label};
            },
        },
        name=pmt
      [Optimise Projection\\Matrix, inner color=col4in, outer color=col4out]
      [Reduce Number of\\Measurements, inner color=col4in, outer color=col4out]
    ]
    [Compressed Sensing\\Theory, inner color=col1in, outer color=col1out, name=cst
    ]
    [Reconstruction\\Algorithms,
      inner color=col3in,
      outer color=col3out,
      where level={3}{tier=tier3}{},
      for tree={
        grow=south,
        child anchor=north,
        parent anchor=south,
        edge path={
          \noexpand\path[color=linecol, rounded corners=5pt, >={Stealth[length=10pt]}, line width=1pt, ->, \forestoption{edge}]
            (!u.parent anchor) -- +(0,-5pt) -|
            (.child anchor)\forestoption{edge label};
          },
      },
      name=ra
      [Convex Relaxation
        [Sparse Signal\\Estimate, rect, name=sse1
        ]
      ]
      [Greedy Pursuits
        [Sparse Signal\\Estimate, rect, name=sse2
        ]
      ]
      [, phantom, calign with current
        [A\\B, phantom
          [Our Work, orect, name=us
            [{Improved Sparse Signal Estimate!}, oellip
            ]
          ]
        ]
      ]
      [Non-Convex\\Minimisation Methods
        [Sparse Signal\\Estimate, rect, name=sse3
        ]
      ]
      [Combinatorial\\Algorithms
        [Sparse Signal\\Estimate, rect, name=sse4
        ]
      ]
    ]
  ]
  \begin{scope}[color=linecol, rounded corners=5pt, >={Stealth[length=10pt]}, line width=1pt, ->]
    \draw (sse2.south) -- (us.north -| sse2.south);
    \draw (sse3.south) -- (us.north -| sse3.south);
    \coordinate (c1) at ($(sse1.south)!2/5!(sse2.south)$);
    \coordinate (c2) at ($(sse3.south)!2/5!(sse4.south)$);
    \draw (sse1.south) -- +(0,-10pt) -| (us.north -| c1);
    \draw (sse4.south) -- +(0,-10pt) -| (us.north -| c2);
    \draw (cst.north) -- (pmt.south);
    \draw (cst.south) -- (ra.north);
  \end{scope}
\end{forest}
\end{document}

non-hierarchical diagram

Of course, the diagram is no longer hierarchical. Rather, it includes several competing hierarchies...

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .