![このようなブロック図をLaTeXで描く方法](https://rvso.com/image/405356/%E3%81%93%E3%81%AE%E3%82%88%E3%81%86%E3%81%AA%E3%83%96%E3%83%AD%E3%83%83%E3%82%AF%E5%9B%B3%E3%82%92LaTeX%E3%81%A7%E6%8F%8F%E3%81%8F%E6%96%B9%E6%B3%95.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 に感謝します。
2回目の編集: 修正を追加https://tex.stackexchange.com/a/513549@cfr の提案に従って。