我怎样才能使小箭头指向正方向?
\documentclass[border=7pt]{standalone}
\usepackage{forest}
\usetikzlibrary{arrows.meta,
chains,
fit,
positioning}
\usepackage{siunitx}
\tikzset{
node distance = 2mm and 0mm,
start chain = A going below,
wbox/.style = {draw, text width=8*1.3 em, inner sep=1mm,
on chain, node contents={}},
gbox/.style = {draw, fill=lightgray, text width=1em,
inner xsep=0mm, inner ysep=1mm,
node contents={}},
every label/.append style = {font=\footnotesize}
}
\begin{document}
\begin{forest}
for tree = {
draw,
minimum height=4ex,
text depth=0.5ex,
anchor=north,
inner sep=1mm,
tw/.style = {text width=#1*1.3 em},
text centered,
%
s sep=1em,
l sep=8ex,
edge={-{Triangle[angle=60:2pt 3]}},
edge path={
\noexpand\path[\forestoption{edge}]
(!u.south) -- (.north);
},
}
[$\mathcal{D}_{blblblblbl}$ \SI{100}{\%}, tw=10,
[$\mathcal{D}_{blblblblbl}$ \SI{80}{\%}, tw=8, name=DS]
[$\mathcal{D}_{blblblb}$ \SI{20}{\%},tw=5]
]
\node [wbox, below=4.5mm of DS, label=left:1]; % A-1
\foreach \i [count=\j from 2] in {2,3,4,k}
{
\ifnum\j=4
\node [wbox, draw=none, label={[yshift=0.8ex]center:$\vdots$}]; % A-5
\else
\node [wbox, label=left:$\i$]; % A-2, ..., A-4
\fi
}
\foreach \i [count=\j from 0]in {1,2,3,5}
{
\ifnum\i=5
\node [gbox, left =of A-\i.east];
\else
\node [gbox, right=\j em of A-\i.west];
\fi
}
\node (n6) [draw=black, rounded corners, dashed,
inner xsep=1em, xshift=-0.5em,
fit=(A-1) (A-5),
label=right: Blalalalalalallalalalal] {};
\draw[-{Triangle[angle=60:2pt 3]}] (DS) -- (n6);
\end{forest}
\end{document}
答案1
只需将最后一行替换\end{forest}
为
\draw[-{Triangle[angle=60:2pt 3]}] (DS.south) -- (DS.south|-n6.north);
这里,(DS.south|-n6.north)
表示 的x分量DS.south
,即箭头的起点, y分量表示n6.noerth
。
\documentclass[border=7pt]{standalone}
\usepackage{forest}
\usetikzlibrary{arrows.meta,
chains,
fit,
positioning}
\usepackage{siunitx}
\tikzset{
node distance = 2mm and 0mm,
start chain = A going below,
wbox/.style = {draw, text width=8*1.3 em, inner sep=1mm,
on chain, node contents={}},
gbox/.style = {draw, fill=lightgray, text width=1em,
inner xsep=0mm, inner ysep=1mm,
node contents={}},
every label/.append style = {font=\footnotesize}
}
\begin{document}
\begin{forest}
for tree = {
draw,
minimum height=4ex,
text depth=0.5ex,
anchor=north,
inner sep=1mm,
tw/.style = {text width=#1*1.3 em},
text centered,
%
s sep=1em,
l sep=8ex,
edge={-{Triangle[angle=60:2pt 3]}},
edge path={
\noexpand\path[\forestoption{edge}]
(!u.south) -- (.north);
},
}
[$\mathcal{D}_{blblblblbl}$ \SI{100}{\%}, tw=10,
[$\mathcal{D}_{blblblblbl}$ \SI{80}{\%}, tw=8, name=DS]
[$\mathcal{D}_{blblblb}$ \SI{20}{\%},tw=5]
]
\node [wbox, below=4.5mm of DS, label=left:1]; % A-1
\foreach \i [count=\j from 2] in {2,3,4,k}
{
\ifnum\j=4
\node [wbox, draw=none, label={[yshift=0.8ex]center:$\vdots$}]; % A-5
\else
\node [wbox, label=left:$\i$]; % A-2, ..., A-4
\fi
}
\foreach \i [count=\j from 0]in {1,2,3,5}
{
\ifnum\i=5
\node [gbox, left =of A-\i.east];
\else
\node [gbox, right=\j em of A-\i.west];
\fi
}
\node (n6) [draw=black, rounded corners, dashed,
inner xsep=1em, xshift=-0.5em,
fit=(A-1) (A-5),
label=right: Blalalalalalallalalalal] {};
\draw[-{Triangle[angle=60:2pt 3]}] (DS.south) -- (DS.south|-n6.north);
\end{forest}
\end{document}
箭头一开始不垂直的原因是你添加了wbox
节点左侧的数字。因此拟合的中心DS
不重合。