如何在 LaTeX 中绘制这样的框图

如何在 LaTeX 中绘制这样的框图

我尝试绘制类似于图中所示的框图,但我无法做到。请有人建议我如何绘制这样的框图。谢谢

我到目前为止尝试过,

\usepackage{forest}
\useforestlibrary{edges}

\begin{forest}
for tree={draw, minimum width=2cm, minimum height=1cm, rounded corners},
forked edges,

[IDS for Automotive CAN Bus System [Deployment Strategy[ECU][CAN][Gateway]][Detection Approach[Specification Based][Anomaly Based[Machine Learning][Hybrid Based][Frequency Based]][Signature Based]][Attacking Technique[DoS][Replay]]]
\end{forest}

我在 pdf 中得到了这种输出。错误输出]1

我想要这个输出

答案1

这在很大程度上改编自这里。每当您想要启动文件夹时,您都需要注入for tree={folder, grow'=0}。您的树有点太宽了,所以我减小了除根节点之外的所有文本宽度。

\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{forest}
\useforestlibrary{edges}
\makeatletter
% remove the stray space https://tex.stackexchange.com/a/513549
\patchcmd{\pgfutilsolvetwotwoleqfloat}
  { \noexpand\pgfmathfloatdivide@}
  {\noexpand\pgfmathfloatdivide@}
  {}{}
\makeatother
\begin{document}
\noindent\begin{forest}
before typesetting nodes={
   if={isodd(n_children("!r"))}{
     for nodewalk/.wrap pgfmath arg={{fake=r,n=#1}{calign with current edge}}{int((n_children("!r")+1)/2)},
   }{},
 },
forked edges,
for tree={draw, minimum width=2cm, minimum height=1cm, rounded corners,
if level=0{}{text width=2cm}},
[IDS for Automotive CAN Bus System 
 [Deployment Strategy,for tree={folder, grow'=0}
  [ECU]
  [CAN]
  [Gateway]
 ]
 [Detection Approach
  [Specification Based]
  [Anomaly Based,for tree={folder, grow'=0}
   [Machine Learning]
   [Hybrid Based]
   [Frequency Based]
  ]
  [Signature Based]
 ]
 [Attacking Technique,for tree={folder, grow'=0}
  [DoS]
  [Replay]
 ]
]
\end{forest}
\end{document}

在此处输入图片描述

showframe只是为了表明这棵树适合(但仅加载几何包就会使页面稍微宽一些)。

编辑:删除了tempcounta/.max={level}{tree},未使用的部分,非常感谢@cfr。

第二次编辑:添加了修复https://tex.stackexchange.com/a/513549,根据@cfr 的建议。

相关内容