节点的布局和定位存在问题。
问题 A&B- 参见绿线。我希望节点(块)处于同一高度。因此,最好将块的底部置于绿线上。(垂直对齐?)
问题 C- 参见蓝色圆圈。我认为这一问题与问题 A 和 B 有关,因为它们的高度不相同。但是,我希望箭头是水平的,而不是略微倾斜。
问题 D- 看到红色块。我希望初始块(黑色)位于新位置(红色),即我希望块稍微向右移动,这样它看起来就不会太拥挤。
妇女权利委员会:
\documentclass{report}
\usepackage[edges]{forest}
\usepackage{pdflscape}
\usepackage{tikz-qtree}
\usepackage{pgfkeys}
\usepackage{graphicx}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{calc,trees,positioning,arrows,chains,shapes.geometric,%
decorations.pathreplacing,decorations.pathmorphing,shapes,%
matrix,quotes,shapes.symbols,plotmarks}
\begin{document}
\begin{landscape}
\tikzset{
block/.style={rectangle, draw, fill=white!20, text width=2.75cm, text centered, rounded corners, minimum height=1.4cm},
line/.style={draw, very thick, color=black!80, -Stealth},
}
\begin{figure}[h]
\centering
{\small
\begin{forest}
arrow to/.style n args=2{%
delay={%
tikz+={%
\draw [every edge, line] () -- (!#1) node [above, midway] {#2};
},
},
!u.s sep+=30pt,
},
before typesetting nodes={%
where n=1{%
edge label/.wrap value={%
node [left,pos=.75, anchor=mid east] {#1}
},
}{%
edge label/.wrap value={%
node [right,pos=.75, anchor=mid west] {#1}
},
},
},
for tree={%
parent anchor=children,
child anchor=parent,
block,
edge={line},
l sep+=10pt,
},
forked edges
[Should we use it or not?
[Type of wave
[XXXXXXXX important?, edge label= HF waves
[Not recommended, edge label=Yes
]
[{XXXXXXXX characteristics}, edge label=No, arrow to={s}{Swell}
[Use with XXXXXXXX care, edge label = Wind
]
]
]
[Which XXXXXXXX parameter?, edge label=LF waves
[XXXXXXXXXX of XXXXX, edge label = Wave height
[Estimation of XXXXXXXX height, edge label = Swell
]
[Potential, edge label = Wind
]
]
[$H_{m0} \leq 100m$, edge label= Wave period
[Potential, edge label = Yes
]
[{Obliquity w.r.t. 123456 XXXXXXXX}, edge label = No, arrow to = {s}{No}
[Not recommended, edge label = Yes
]
]
]
[Yes, edge label = Resonant modes
]
]
]
]
\end{forest}
}
\caption{Decision tree } \label{Decisiontree}
\end{figure}
\end{landscape}
\end{document}
下一步该如何做?
此代码源自这里并进行了修正。
答案1
为了回答这个问题,我编辑了您的示例,删除了无关内容,并添加了编译失败并出现错误的内容。请确保发布的示例可以编译,除非问题涉及特定错误,在这种情况下,示例应该会产生相关错误。
问题 A、B 和 C 可以通过告诉 Forest 将每个级别中的所有节点对齐到相同的来解决tier
。添加以下内容可for tree
实现此目的:
tier/.wrap pgfmath arg={tier #1}{level()},
如果问题 D 只是针对单个节点的一次性调整,最简单的方法可能是增加s
该节点的配额,但这需要推迟到节点都挤满之后。例如,添加
before computing xy={s'+=30pt}
到相关节点将其30pt
向右移动。
这是一个完整的例子:
\documentclass[border=10pt,multi,tikz]{standalone}
\usepackage[edges]{forest}
\usetikzlibrary{arrows.meta}
\begin{document}
\tikzset{
block/.style={draw, fill=white!20, text width=2.75cm, text centered, rounded corners, minimum height=1.4cm},
line/.style={draw, very thick, color=black!80, -Stealth},
}
\begin{forest}
arrow to/.style n args=2{%
delay={%
tikz+={%
\draw [every edge, line] () -- (!#1) node [above, midway] {#2};
},
},
!u.s sep+=30pt,
},
before typesetting nodes={%
where n=1{%
edge label/.wrap value={%
node [left,pos=.75, anchor=mid east] {#1}
},
}{%
edge label/.wrap value={%
node [right,pos=.75, anchor=mid west] {#1}
},
},
},
for tree={%
parent anchor=children,
child anchor=parent,
anchor=south,
block,
edge={line},
l sep+=10pt,
tier/.wrap pgfmath arg={tier #1}{level()},
},
forked edges,
[Should we use it or not?
[Type of wave
[XXXXXXXX important?, edge label= HF waves
[Not recommended, edge label=Yes
]
[{XXXXXXXX characteristics}, edge label=No, arrow to={s}{Swell}
[Use with XXXXXXXX care, edge label = Wind
]
]
]
[Which XXXXXXXX parameter?, edge label=LF waves
[XXXXXXXXXX of XXXXX, edge label = Wave height
[Estimation of XXXXXXXX height, edge label = Swell
]
[Potential, edge label = Wind
]
]
[$H_{m0} \leq 100m$, edge label= Wave period
[Potential, edge label = Yes
]
[{Obliquity w.r.t. 123456 XXXXXXXX}, edge label = No, arrow to = {s}{No}
[Not recommended, edge label = Yes
]
]
]
[Yes, edge label = Resonant modes, before computing xy={s'+=30pt}
]
]
]
]
\end{forest}
\end{document}
产生