如何在 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 的建議。

相關內容