3

I have to make a literature review taxonomy for my final thesis, highlighting the salient features of each paper referred, its categories etc. I want to represent this diagrammatically using a hierarchy (something similar to the picture below)

enter image description here

How can this be done using Latex? I do not want to use any diagramming software as I have to maintain citations for the papers in the taxonomy. I looked at the forest package example available here (posted by @skpblack), and am trying to use it, but I am not sure how to customize this to the plain style that I need. Can someone please help me with this? Thanks for any help in advance.

EDIT: added a MWE

\documentclass[12pt,a4paper,twoside, index, tikz]{book}

%for drawing lit survey hierarchies
\usepackage{tikz}
\usetikzlibrary{trees}

%for drawing lit survey trees
\usetikzlibrary{arrows.meta, shapes.geometric, calc, shadows}
\colorlet{linecol}{black!75}

\usepackage{forest}
\usepackage{newfloat}
    \DeclareFloatingEnvironment[fileext=lod]{Figure} %for adding captions

    \forestset{/.style=
               {
                 {for tree=
                   {parent anchor=south, 
                    child anchor=north,
                    align=center
                    l+=1.5cm}
                  }
               }
              }

    \begin{document}
        \pgfkeys{/forest,
          my rounded corners/.append style={rounded corners=2pt},
        }
        \begin{forest}
          for tree={
           %   font=\sffamily,
              line width=1pt,
              draw=linecol,
         %     drop shadow,
              fit=rectangle,
              edge={color=linecol, >={Triangle[]}, ->},
              where level=0{%
                l sep+=5pt,
                calign=child,
                calign child=2,
              %  inner color=green!80,
             %   outer color=green,
                align=center,
                my rounded corners,
                for descendants={%
                  calign=first,
                },
              }{%
                where level=1{%
                  %inner color=green!80,
                  %outer color=green,
                  my rounded corners,
                  align=center,
                  parent anchor=south west,
                  tier=three ways,
                  for descendants={%
                    child anchor=west,
                    parent anchor=west,
                    align=left,
                    anchor=west,
        %            inner color=MistyRose1!80,
         %           outer color=MistyRose1,
                    edge path={
                      \noexpand\path[\forestoption{edge}]
                      (!to tier=three ways.parent anchor) |-
                      (.child anchor)\forestoption{edge label};
                    },
                  },
                }{}%
              },
          }
          [Drawing Diagrams
            [Defining node\\and arrow styles
              [Setting shape
                [Choosing colour
                  [Adding shading]
                ]
              ]
            ]
            [Positioning\\the nodes
              [Using a matrix
                [Absolutely
                  [Relatively
                    [Using overlays]
                  ]
                ]
              ]
            ]
            [Drawing arrows\\between nodes
              [Default arrows
                [Arrow library
                  [Re-sizing tips
                     [Shortening
                       [Bending]
                     ]
                  ]
                ]
              ]
            ]
          ]
        \end{forest}
    \end{document}

This currently gives me the following output - enter image description here

I'm not sure how to edit this further to get the display I want. Tried to edit other parts of the code (like that which produces the bounding rectangle etc) but that gave me errors.

EDIT #2: (UPDATE)

I used the exact code provided by @cfr in the edited answer, in my document (book class), and was repeatedly getting a "Missing \endcsname inserted. \bgroup \end{forest}" error.. It worked when I commented out fancyhdr package. But right now I am getting the following display. The horizontal arrows pointing to the level 3 child nodes are too long and hence overlap over each other. What did I do wrong? (Sorry, I did not know how to add the latest screenshot in the comments section.)

enter image description here

  • That's not an MWE. You've just copied the code from somewhere else - without attributing it to its author, even. It has nothing to do with your diagram. (I know you've copied it because I recognise it, although I can't remember the author.) An MWE would at least involve you typing some of the content you want to appear in the diagram and making some attempt to produce the diagram you want to produce. – cfr Aug 30 '15 at 2:37
  • @cfr, I've already said that I have seen the example available at this link and have been trying to use it. I will add an explicit attribution to the author. I am not trying to take any credit for others work here. – Skarth Aug 30 '15 at 2:51
4

Update

If you don't mind restructuring the tree a bit, you can get something a bit closer to your target. I've also tried using the angles library here to draw the arc at the top.

If you use an empty node for the second level (below the tier of sub-headings), then set the sub-sub-headings as children of that level, you can use a further child, where desired, and get a better alignment of the sub-sub-headings.

updated tree

Here's the code:

\documentclass[12pt, border=20pt, tikz]{standalone}
% based on skpblack's answer at http://tex.stackexchange.com/questions/206971/diagram-using-forest-package, modified by skarth at http://tex.stackexchange.com/q/263749/.
%for drawing lit survey trees
\usetikzlibrary{arrows.meta,angles,quotes}
\colorlet{linecol}{black!75}
\usepackage{forest}

\tikzset{
  my rounded corners/.append style={rounded corners=2pt},
}

\begin{document}
    \begin{forest}
      for tree={
        line width=1pt,
        if={level()<2}{
          my rounded corners,
          draw=linecol,
        }{},
        edge={color=linecol, >={Triangle[]}, ->},
        if level=0{%
          l sep+=1.5cm,
          align=center,
          parent anchor=south,
          tikz={
            \path (!1.child anchor) coordinate (A) -- () coordinate (B) -- (!l.child anchor) coordinate (C) pic [draw, angle radius=20mm, every node/.append style={fill=white}, "based on"] {angle};
          },
        }{%
          if level=1{%
            parent anchor=south west,
            child anchor=north,
            tier=parting ways,
            align=center,
            font=\bfseries,
            for descendants={
              child anchor=west,
              parent anchor=west,
              anchor=west,
              align=left,
            },
          }{
            if level=2{
              shape=coordinate,
              no edge,
              grow'=0,
              calign with current edge,
              xshift=20pt,
              for descendants={
                parent anchor=south west,
                l sep+=-20pt
              },
              for children={
                edge path={
                  \noexpand\path[\forestoption{edge}] (!to tier=parting ways.parent anchor) |- (.child anchor)\forestoption{edge label};
                },
                font=\bfseries,
                for descendants={
                  no edge,
                },
              },
            }{},
          },
        }%
      },
      [Main Heading
        [Attributes
          [
            [Type of attributes
              [1. a\\2. b]
            ]
            [Weight of attributes
              [$w <$ 1g\\1g $\leq w \leq$ 5g\\5g $\leq w \leq$ 10g\\10g $\leq w$]
            ]
            [Number of attributes
              [10\\100\\1000]
            ]
          ]
        ]
        [Support value
          [
            [Support value
              [Positive\\Negative]
            ]
            [Variations
              [Optimised\\Fuzzy]
            ]
            [Absolute value
              [Fractional\\Decimal\\Normalised]
            ]
            [Relative value
              [Fractional\\Decimal\\Normalised]
            ]
          ]
        ]
        [Constraints
          [
            [None]
            [Some
              [One\\A few\\Many\\Lots]
            ]
            [Statistical comparisons
              [Median\\Mean\\Mode\\Standard deviation\\Reliability\\T test]
            ]
          ]
        ]
        [Concept taxonomy
          [
            [Categories]
          ]
        ]
        [Types of data
          [
            [Noumena
              [Thing 1-in-itself\\Thing 2-in-itself\\Thing 3-in-itself]
            ]
            [Phenomena
              [Appearance 1\\Appearance 2\\Appearance 3\\Appearance 4]
            ]
          ]
        ]
      ]
      \end{forest}
\end{document}

This looks a bit better to me in part because doing away with fit=rectangle makes the tree more compact, which I think makes the structure clearer.

Original (without need for extra nodes)

\documentclass[12pt, border=20pt, tikz]{standalone}
%for drawing lit survey trees
\usetikzlibrary{arrows.meta}
\colorlet{linecol}{black!75}
\usepackage{forest}

\tikzset{
  my rounded corners/.append style={rounded corners=2pt},
}

\begin{document}
    \begin{forest}
      for tree={
        line width=1pt,
        if={level()<2}{
          my rounded corners,
          draw=linecol,
        }{},
        fit=rectangle,
        edge={color=linecol, >={Triangle[]}, ->},
        if level=0{%
          l sep+=1.5cm,
          for descendants={%
            calign=first,
          },
          align=center,
          parent anchor=south,
          tikz={
            \draw (!1.north |- .south) +(0,-5pt) coordinate (a) [out=-30, in=-150] to node [midway, above=5pt] {Something here} (!l.north |- a);
          },
        }{%
          if level=1{%
            parent anchor=south west,
            child anchor=north,
            tier=three ways,
            align=center,
            for descendants={%
              child anchor=west,
              parent anchor=west,
              align=left,
              anchor=west,
              xshift=-20pt,
              edge path={
                \noexpand\path[\forestoption{edge}]
                (!to tier=three ways.parent anchor) |-
                (.child anchor)\forestoption{edge label};
              },
            },
          }{}%
        },
      }
      [Drawing Diagrams
        [Defining node\\and arrow styles
          [Setting shape
            [Choosing colour
              [Adding shading]
            ]
          ]
        ]
        [Positioning\\the nodes
          [Using a matrix
            [Absolutely
              [Relatively
                [Using overlays]
              ]
            ]
          ]
        ]
        [Drawing arrows\\between nodes
          [Default arrows\\1. something\\2. else
            [Arrow library
              [Re-sizing tips
                 [Shortening
                   [Bending]
                 ]
              ]
            ]
          ]
        ]
      ]
    \end{forest}
\end{document}

hierarchy

  • Thank you @cfr. This is great. You help is much appreciated. – Skarth Aug 30 '15 at 3:52
  • @Skarth See also edit for a version which may be closer to what you want. It involves restructuring the tree a bit more, though. – cfr Aug 30 '15 at 16:28
  • Once again, thank you for your time and effort @cfr. This new version is simply awesome. You made my day. – Skarth Aug 31 '15 at 9:25
  • @Skarth Great - I'm glad you like it. As I say, it requires a bit more restructuring, but I thought the result was worth it ;). – cfr Aug 31 '15 at 11:28
  • It's so useful, @cfr.. I am completely new to tikz/forest packages, and am amazed at how versatile they are, but the code is way beyond my capability right now. By the way, I used your exact code in a standalone document and it works great. But when I add this to my document (book class), am repeatedly getting a _"Missing \endcsname inserted. <to be read again> \bgroup \end{forest}" _ error.. After researching on TEX, I tried many things, but now have tried every possibility, trying to solve this. Any thoughts on what is going wrong here ? Thanks in advance. – Skarth Sep 2 '15 at 2:18

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.