这件事让我沮丧了一两个小时。通常我会在每张图片中局部维护森林风格。有一片森林让我抓狂不已,但我确信我做的事情完全是愚蠢的。
下面的 MWE 可以按原样编译,但当注释掉 tikzset 并且取消注释两个相同的注释行时,将无法编译。为什么不行?错误是“我不知道密钥 '/tikz/belowab”
\documentclass{article}
\usepackage{forest}
\begin{document}
\tikzset{
aboveab/.style={midway, above, font=\scriptsize, text width=1.5cm, align=center},
belowab/.style={midway, below, font=\scriptsize, text width=1.5cm, align=center}}
\begin{forest}
%aboveab/.style={midway, above, font=\scriptsize, text width=1.5cm, align=center},
%belowab/.style={midway, below, font=\scriptsize, text width=1.5cm, align=center},
for tree={
grow=east,
draw=blue,
circle,
line width=0.2pt,
parent anchor=east,
child anchor=west,
edge={draw=blue},
edge label={\Huge\color{black}},
edge path={
\noexpand\path[\forestoption{edge}]
(!u.parent anchor) -- ([xshift=-1.6cm].child anchor) --
(.child anchor)\forestoption{edge label};
},
l sep=2cm,
}
[,rectangle, s sep=35pt,
[,edge label={node[belowab]{Text}}
[,edge label={node[belowab]{Text}}
]
[,edge label={node[aboveab]{Text}}
]
]
[,edge label={node[aboveab]{Text}}
[,edge label={node[belowab]{Text}}
]
[,edge label={node[aboveab]{text}}
]
]
]
\end{forest}
\end{document}
但是,以下形式的森林前缀将起作用
\begin{forest}
parentab/.style={align=center,text width=2cm,fill=green!20,rounded corners=2pt},
childab/.style={align=center,text width=3.5cm,fill=green!50,rounded corners=6pt},
grandchildab/.style={fill=pink!50,text width=3.3cm},
for tree={%
thick,
drop shadow,
l sep=0.6cm,
s sep=0.8cm,
node options={draw,font=\sffamily},
edge={semithick,-Latex},
where level=0{parentab}{},
where level=1{
minimum height=1cm,
childab,
parent anchor=south west,
tier=p,
l sep=0.25cm,
for descendants={%
grandchildab,
minimum height=0.6cm,
anchor=150,
edge path={
\noexpand\path[\forestoption{edge}]
(!to tier=p.parent anchor) |-(.child anchor)\forestoption{edge label};
},
}
}{},
}
[Drawing\\diagrams
[Defining node and arrow styles
同样这也有效
\begin{forest}
m/.style={fill=color1!30},
f/.style={fill=color1!60,text=white},
h/.style={fill=color2!30},
for tree={
child anchor=west,
parent anchor=east,
grow'=east,%
%minimum size=1cm,%new possibility (note how did \\
text width=4cm,%
draw,
anchor=west,
edge path={
\noexpand\path[\forestoption{edge}]
(.child anchor) -| +(-5pt,0) -- +(-5pt,0) |-
(!u.parent anchor)\forestoption{edge label};
},
}
[Delivery Strategy\\for H/4154/2014
[Procurement Strategy
[Proposal overview
[Stakeholders]
[Vulnerabilities,f]
[Overview programme,f]
[Staff skill requirements]
]
[Programme]
[Market-engagement\\strategy]
[Tender strategy]
[Engagement of personnel]
[Compliance \& \\Governance strategy,m]
]
[Rationale for\\procurement
[Assumed background,h]
[Rationale for recommendations,m
[Legal requirements,m]
[Client requirements,m]
]
]
]
\end{forest}
答案1
注释掉\tikzset
并使用本地设置获得的错误消息告诉您问题:
! Package pgfkeys Error: I do not know the key '/tikz/belowab' and I am going
to ignore it. Perhaps you misspelled it.
密钥处理器需要以下形式的密钥/tikz/...
,因此您需要将/tikz
密钥的本地路径设置为:
\documentclass{article}
\usepackage{forest}
\begin{document}
\begin{forest}
/tikz/aboveab/.style={midway, above, font=\scriptsize, text width=1.5cm, align=center},
/tikz/belowab/.style={midway, below, font=\scriptsize, text width=1.5cm, align=center},
for tree={
grow=east,
draw=blue,
circle,
line width=0.2pt,
parent anchor=east,
child anchor=west,
edge={draw=blue},
edge label={\Huge\color{black}},
edge path={
\noexpand\path[\forestoption{edge}]
(!u.parent anchor) -- ([xshift=-1.6cm].child anchor) --
(.child anchor)\forestoption{edge label};
},
l sep=2cm,
}
[,rectangle, s sep=35pt,
[,edge label={node[belowab]{Text}}
[,edge label={node[belowab]{Text}}
]
[,edge label={node[aboveab]{Text}}
]
]
[,edge label={node[aboveab]{Text}}
[,edge label={node[belowab]{Text}}
]
[,edge label={node[aboveab]{text}}
]
]
]
\end{forest}
\end{document}
以下解释由萨索·日瓦诺维奇(软件包作者)comment
:
当在节点规范中(即在内容之后)
forest
遇到未知键(在路径中)时,它会自动将键附加到键列表节点选项中,该选项在创建节点时传递给 tikz(然后路径自动更改为)。创建边标签时,您将直接在 tikz 中创建节点:请注意,使用的是 tikz 语法,节点选项放在方括号中。因此,必须在路径中创建此类样式。/forest
/tikz
edge label={node[aboveab]{Text}}
/tikz