Latex Forest 超越了页面边界吗?

Latex Forest 超越了页面边界吗?

我在使用 latex 中的 forest 包绘制层次树时遇到问题,如下所示:

   \begin{forest}
    for tree={
      l sep=1cm,
      s sep=0.1cm,
      minimum height=0.8cm,
      minimum width=2cm,
      align=center,
      parent anchor=south,
      child anchor=north,
      font=\sffamily,
      edge={thick, -{Stealth[]}},
      edge path={
    \noexpand\path [draw, \forestoption{edge}] (!u.parent anchor) -- +(0,-10pt) -| (.child anchor)\forestoption{edge label};
      },
      if level=0{
    inner xsep=0pt,
    tikz={\draw [thick] (.south east) -- (.south west);}
      }{}
    }
    [Anomaly Detection
    [Supervised Anomaly\\Detection
      [Support Vector\\Machine]
      [Bayesian\\Network]
      [Neural\\Networks
        [Deep\\Learning
          [AutoEncoders]
          [LSTM]
          [GRU]
        ]
      ]
      [Rule-based]
    ]
    [Statistical\\Anomaly\\Detection
      [Mixture\\Models]
      [Signal\\Processing\\Techniques]
      [Principal\\Component\\Analysis]
    ]
    [Information\\Theory
      [Correlation\\Analysis]
    ]
    [Clustering-based
      [Regular\\Clustering]
      [Co-clustering]
    ]
      ]
  \end{forest}

不幸的是,结果并不像我预期的那样:

在此处输入图片描述

答案1

adjustbox包裹包裹你的森林。这个问题问类似的问题。

\usepackage{adjustbox}

...

\begin{adjustbox}{width=\linewidth}
\begin{forest}
    for tree={
      l sep=1cm,
      s sep=0.1cm,
      minimum height=0.8cm,
      minimum width=2cm,
      align=center,
      parent anchor=south,
      child anchor=north,
      font=\sffamily,
      edge={thick, -{Stealth[]}},
      edge path={
    \noexpand\path [draw, \forestoption{edge}] (!u.parent anchor) -- +(0,-10pt) -| (.child anchor)\forestoption{edge label};
      },
      if level=0{
    inner xsep=0pt,
    tikz={\draw [thick] (.south east) -- (.south west);}
      }{}
    }
    [Anomaly Detection
    [Supervised Anomaly\\Detection
      [Support Vector\\Machine]
      [Bayesian\\Network]
      [Neural\\Networks
        [Deep\\Learning
          [AutoEncoders]
          [LSTM]
          [GRU]
        ]
      ]
      [Rule-based]
    ]
    [Statistical\\Anomaly\\Detection
      [Mixture\\Models]
      [Signal\\Processing\\Techniques]
      [Principal\\Component\\Analysis]
    ]
    [Information\\Theory
      [Correlation\\Analysis]
    ]
    [Clustering-based
      [Regular\\Clustering]
      [Co-clustering]
    ]
      ]
  \end{forest}
\end{adjustbox}

在此处输入图片描述

答案2

我会考虑树水平生长的可能性,使用\small字体大小和不是使用adjustbox

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

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
    \begin{center}
\begin{forest}
    for tree={
      align=left,
      edge = {draw, semithick, -stealth},
    anchor = west,
      font = \small\sffamily\linespread{.84}\selectfont,
      forked edge,          % for forked edge
             grow = east,
            s sep = 0mm,    % sibling distance
            l sep = 8mm,    % level distance
         fork sep = 4mm,    % distance from parent to branching point
         tier/.option=level
            }
[Anomaly\\ Detection
    [Supervised\\ Anomaly\\Detection
      [Support\\ Vector\\Machine]
      [Bayesian\\Network]
      [Neural\\Networks
        [Deep\\Learning
          [AutoEncoders]
          [LSTM]
          [GRU]
        ]
      ]
      [Rule-based]
    ]
    [Statistical\\Anomaly\\Detection
      [Mixture\\Models]
      [Signal\\Processing\\Techniques]
      [Principal\\Component\\Analysis]
    ]
    [Information\\Theory
      [Correlation\\Analysis]
    ]
    [Clustering\\ based
      [Regular\\Clustering]
      [Co-clustering]
    ]
]
\end{forest}
    \end{center}
\end{document}

在此处输入图片描述

(红线表示页面布局(文本边框))

相关内容