![如何在 LaTeX 中繪製這樣的框圖](https://rvso.com/image/405356/%E5%A6%82%E4%BD%95%E5%9C%A8%20LaTeX%20%E4%B8%AD%E7%B9%AA%E8%A3%BD%E9%80%99%E6%A8%A3%E7%9A%84%E6%A1%86%E5%9C%96.png)
我試圖繪製一個類似於圖中所示的框圖,但我無法做到這一點,請有人建議我一種繪製此類框圖的方法。謝謝
到目前為止我嘗試過,
\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}
答案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 的建議。