3

I am trying to make a tree using forest. It is within minipage environment. But the tree does not aligns with the center of the page. Moreover I would like it if the subsequent levels too were centered around one vertical line.

\documentclass{article}
\usepackage{forest}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{caption}
\begin{document}
\begin{minipage}{\linewidth}
\makebox[\linewidth]{
\begin{forest}
for tree={
grow'=east,draw=black,parent anchor=east,child anchor=west, align=center,
edge path={
    \noexpand\path[\forestoption{edge}]
    (!u.parent anchor) -- +(10pt,0) |- 
    (.child anchor)\forestoption{edge label};
},
}
[Microfabrication,
[Subtractive, 
[\begin{minipage}{4.5cm}{
  \begin{enumerate}
  \item \noindent $\mu$ -EDM
  \item \noindent $\mu$ -ECM
  \item \noindent LBM
  \item \noindent EBM
  \item \noindent Micro-Cutting
  \item \noindent PCM
  \end{enumerate}}
  \end{minipage}]
  ]
  [Additive
  [\begin{minipage}{4.5cm}{
  \begin{enumerate}
  \item Surface Coating
  \item Direct Writing
  \item Stereolithography
  \item Chemical \\ Deposition
  \item Polymer \\ Deposition
  \end{enumerate}}
  \end{minipage}]
  ]
  [Lithography Based
  [\begin{minipage}{4.5cm}{
  \begin{enumerate}
  \item Photolithography
  \item LIGA
  \item Soft Lithography
  \item X-Ray \\ Lithography
  \end{enumerate}}
  \end{minipage}]
  ]
  [Hybrid
  [\begin{minipage}{4.5cm}{
  \begin{enumerate}
  \item  Surface Coating
  \item  Direct Writing
  \item  Stereolithography
  \item  Chemical Deposition
  \item  Polymer Deposition
  \end{enumerate}}
  \end{minipage}]
  ]
  ]
  \end{forest}}
  \captionof{figure}{Microfabrication Techniques}
  \end{minipage}
  \end{document}

Here is the output Output

3

I dispensed with the minipage environment and I made it easier to handle. Also, I centered the titles and streched the boxes with the items.

enter image description here

\documentclass{article}
\usepackage[left=5pt,right=5pt,top=10pt,bottom=10pt]{geometry}
\usepackage{forest}
\usepackage{caption}
\newcommand{\vs}{\vspace{2mm}}

\begin{document}

\begin{figure}
\centering
\resizebox{0.9\textwidth}{!}{%
\begin{forest}
    for tree={
    child anchor=west,
    parent anchor=east,
    grow'=east, text centered,
    text width=5cm,
    draw,
    anchor=west,
    edge path={
    \noexpand\path[\forestoption{edge}]
        (.child anchor) -| +(-2pt,0) -- +(-8pt,0) |-
        (!u.parent anchor)\forestoption{edge label};
            },
    }
    [\centering Microfabrication
        [{Subtractive}
            [{\begin{enumerate}
                \item $\mu$ -EDM
                \item $\mu$ -ECM
                \item LBM
                \item EBM
                \item Micro-Cutting
                \item PCM
            \end{enumerate}}\vs
        ]
    ]
    [Additive
            [{\begin{enumerate}
                \item Surface Coating
                \item Direct Writing
                \item Stereolithography
                \item Chemical Deposition
                \item Polymer Deposition
            \end{enumerate}}\vs
        ]
    ] 
    [Lithography Based
            [{\begin{enumerate}
                \item Photolithography
                \item LIGA
                \item Soft Lithography
                \item X-Ray Lithography
            \end{enumerate}}\vs
        ]
    ]
    [Hybrid
            [{\begin{enumerate}
                \item  Surface Coating
                \item  Direct Writing
                \item  Stereolithography
                \item  Chemical Deposition
                \item  Polymer Deposition
            \end{enumerate}}\vs
        ]
    ]
]
\end{forest}}
\caption{Microfabrication Techniques}
\end{figure}
\end{document}
  • ThanX! This worked great. Though I let go of the {geometry} package as it was clashing with something. But, would this tree be floating or fixed on the page? – Siddharth Nov 23 '17 at 6:10
  • Yes, you can get rid of geometry package in preamble. I have to say, it was only for the printing of the image, I forgot to remove it. You do not need to use that since it would compromise the rest of the document. – Cragfelt Nov 23 '17 at 15:30
3

like this?

enter image description here

nodes with lists are horizontally aligned with forest option tier/.pgfmath=level(). for list is employed enumitem package. instead minipage in nodes with lists is used forest option where n children=0{text width=4cm}{},:

\documentclass{article}
\usepackage[edges]{forest}
\usepackage{enumitem}
\usepackage{caption}

\begin{document}
    \begin{figure}[ht]
    \setlist{nosep, leftmargin=*, before= \vspace{-0.5\baselineskip}}
    \centering
\begin{forest}
  for tree={
    draw=black,
    where n children=0{text width=4cm}{},   % <---
    grow'=0,
    l sep=2em,                  
    forked edge,
    fork sep=1em,                           % <---
    anchor=west,
    tier/.pgfmath=level(),                  % <---
    },
[Microfabrication
 [Subtractive
  [\begin{enumerate}                        % no minipage
    \item $\mu$ -EDM
    \item $\mu$ -ECM
    \item LBM
    \item EBM
    \item Micro-Cutting
    \item PCM
   \end{enumerate}]
  ]
 [Additive
  [\begin{enumerate}
    \item Surface Coating
    \item Direct Writing
    \item Stereolithography
    \item Chemical Deposition
    \item Polymer Deposition
   \end{enumerate}]
  ]
 [Lithography Based
  [\begin{enumerate}
    \item Photolithography
    \item LIGA
    \item Soft Lithography
    \item X-Ray Lithography
   \end{enumerate}]
  ]
  [Hybrid
  [\begin{enumerate}
    \item  Surface Coating
    \item  Direct Writing
    \item  Stereolithography
    \item  Chemical Deposition
    \item  Polymer Deposition
   \end{enumerate}]
   ]
 ]
\end{forest}
  \caption{Microfabrication Techniques}
  \label{fig:forest}
    \end{figure}
\end{document}

addendum (1): if you more like to have equal width of all nodes in forest, then for for tree options use the following:

  for tree={
    draw=black,
    text width=38mm,                         % <---
    text centered,                           % <---
    grow'=0,
    l sep=2em,
    forked edge,
    fork sep=1em,                           
    anchor=west,
    },

and you will obtain:

enter image description here

in comparison with your mwe i put image in float environment figure with option [ht] which ensure that diagram will be in text where is inserted, if on page is enough place for it or in opposite case on the top of the next page.

addendum (2):

one more example (just for exercise). with for tree options:

  for tree={
    draw=black,
    where n children=1{text width=2cm, text centered}{},  % <---
    where n children=0{text width=4cm}{},                 % <---
    grow'=0,
    l sep=2em,
    forked edge,
    fork sep=1em,
    anchor=west,
    },

you will obtain:

enter image description here

  • Thanks. This too would work good, but Cragfelt's output looks a bit better. – Siddharth Nov 23 '17 at 6:19
  • @Siddharth, i'm just curious: in which sense cragfelt's answer looks better? i made add an option with equal width nodes in diagram. is this what you looking for? – Zarko Nov 23 '17 at 8:21
  • Well, yes nodes with equal width do look better. So now your output is similar to his. But I am new to Latex, so I am looking for simplistic solutions. His solution seemed more simplistic to me. It is very much possible that your code could be better, but I am no judge of that. Thanks. – Siddharth Nov 23 '17 at 13:12
  • @Siddharth, in your question you not mentioned, that you like to have equal width of nodes. and people has different taste ... since you select forest, which is very powerful but demanding package, i expect, that you are familiar with it or at least on the way to learn more about it. i show you some possibilities how to use it (i still learn it). if you more prefer Cragfelt answer, than please accept it. – Zarko Nov 23 '17 at 13:25
  • Yes, I am trying to learn forest and I also do accept I hadn't mentioned that I need equal width nodes. – Siddharth Nov 24 '17 at 5:55

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.