如何使用森林来对齐我的树?

如何使用森林来对齐我的树?

我正在尝试使用森林制作一棵树。它在 minipage 环境中。但树与页面中心不对齐。此外,如果后续级别也以一条垂直线为中心,我会更喜欢。

\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}

输出如下 输出

答案1

我放弃了minipage环境,让它更容易处理。此外,我将标题居中,并将项目框拉长。

在此处输入图片描述

\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}

答案2

像这样?

在此处输入图片描述

forest带有列表的节点使用选项水平对齐tier/.pgfmath=level()。对于列表,使用enumitem包。minipage在带有列表的节点中,改用forest选项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}

附录(1): 如果您更希望所有节点的宽度相等forest,则for tree使用以下选项:

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

您将获得:

在此处输入图片描述

与你的相比姆韦我将图像放在浮动环境中figure,并选择[ht]确保图表位于插入的文本中,如果页面上有足够的空间,或者相反,位于下一页的顶部。

附录(2):

再举一个例子(仅用于练习)。for tree选项如下:

  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,
    },

你将获得:

在此处输入图片描述

相关内容