我正在尝试在 beamer 动画中使用由 forest 包构建的树。为了揭示树的一部分(我希望它从下到上显示出来),我使用了使用投影机叠加森林生成的树木稍微修改一下,让它只隐藏当前节点,而不隐藏整个子树。
现在的问题是,我可以通过简单地添加选项来手动隐藏节点visible on=<#>
,但由于某种原因,通过 where 语句添加选项时这不起作用。
问题的第二部分是我在尝试清理代码时发现的一个奇怪现象 - 当组合这两个forestset
选项时,它不再隐藏边和节点,而只隐藏节点。 (现在即使手动添加可见性语句。
我正在尝试的代码如下:(在树中我添加了一个位置
\documentclass[]{beamer}
\usepackage[linguistics,external]{forest}
\usepackage{tikz}
\tikzset{highlight/.style={darkred,very thick},}
\tikzset{positive/.style={fill=examplegreen}}
\tikzset{negative/.style={fill=examplered}}
\colorlet{parameterblue}{rgb:cyan,2;white,4;blue,3}
\colorlet{examplegreen}{rgb:green,4;white,4;black,1}
\colorlet{examplered}{rgb:orange,2;red,3;white,4}
\colorlet{darkred}{red!80!black}
\colorlet{darkgreen}{green!80!black}
\newcommand{\plus}{\color{darkgreen}{$+$}}
\newcommand{\minus}{\color{darkred}{$-$}}
\tikzset{
invisible/.style={opacity=0,text opacity=0},
visible on/.style={alt={#1{}{invisible}}},
alt/.code args={<#1>#2#3}{%
\alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
},
beschr/.style={remember picture,overlay,font=\small},
highlight on/.style={{alt=#1{highlight}{}}},
}
\forestset{
highlight on/.style={/tikz/highlight on={#1},}
}
\forestset{
visible on/.style={
% for tree={
/tikz/visible on={#1},
for children={
edge={/tikz/visible on={#1}}}
}
}
\begin{document}
\begin{frame}
\begin{forest}
%aligns the bottom lines
where n children=0{tier=terminal,!u.tier=second,!uu.tier=third}{math content},
where n children=0{!u.visible on=<2->,!uu.visible on=<3->,!uuu.visible on=<4->}{},
for tree={l sep+=1em,}
[ {\{m_7,m_{11}\}}
[{\{m_8,m_9\}}
[{\{m_1,m_2,m_4\}}
[{\{m_1,m_3\}}
[1][2],
]
[{\{\dots\}}
[3][4\\\plus]
]
]
[{\{m_7\}}
[ {\{m_7\}}
[{5\onslide<5->{\\\minus}},for ancestors={edge={highlight on=<5->}},edge={highlight on=<5->}][6]
]
[ {\{\dots\}}
[7\\\plus][8\\\plus]
]
]
]
[{\{\dots\}},visible on=<2->
[{\{\dots\}}[9\\\minus][10]]
[{\{\dots\}}[11][12\\\minus]]
]
]
\end{forest}
\end{frame}
\end{document}
对于问题的第二部分,我交换了包含两个 forestset 语句的块
\forestset{
highlight on/.style={/tikz/highlight on={#1},}
}
\forestset{
visible on/.style={
% for tree={
/tikz/visible on={#1},
for children={
edge={/tikz/visible on={#1}}}
}
}
通过单个 forestset 语句
\forestset{
highlight on/.style={/tikz/highlight on={#1},}
visible on/.style={
% for tree={
/tikz/visible on={#1},
for children={
edge={/tikz/visible on={#1}}}
}
}
然后它没有隐藏任何边缘。关于我在这里遗漏了什么,有什么建议吗?
答案1
可能就是这样。这是我使用的某些自定义的修改版本,因此代码的来源以注释的形式包含在内。
\documentclass[]{beamer}
\usepackage[linguistics]{forest}
\usepackage{tikz}
\tikzset{
highlight/.style={darkred,very thick},
positive/.style={fill=examplegreen},
negative/.style={fill=examplered},
}
\colorlet{parameterblue}{rgb:cyan,2;white,4;blue,3}
\colorlet{examplegreen}{rgb:green,4;white,4;black,1}
\colorlet{examplered}{rgb:orange,2;red,3;white,4}
\colorlet{darkred}{red!80!black}
\colorlet{darkgreen}{green!80!black}
\newcommand{\plus}{\color{darkgreen}{$+$}}
\newcommand{\minus}{\color{darkred}{$-$}}
\tikzset{
invisible/.style={opacity=0,text opacity=0},
visible on/.style={alt={#1{}{invisible}}},
alt/.code args={<#1>#2#3}{%
\alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
},
highlight on/.style={{alt=#1{highlight}{}}},
}
\forestset{
visible on/.style={% developed by Qrrbrbirlbel (http://tex.stackexchange.com/a/112471/)
for tree={%
/tikz/visible on={#1},
edge={/tikz/visible on={#1}}}},
highlight on/.style={%
/tikz/highlight on={#1},
edge={/tikz/highlight on={#1}}},
highlight edge on/.style={%
edge={/tikz/highlight on={#1}}},
declare toks={no node before}{1},
declare toks={no edge before}{1},
declare count={gweladwy}{1},
declare count={sleidiau}{1},
not before/.style={%
no node before=#1,
for children={%
no edge before=#1}},
bottom up/.style={% based on Qrrbrbirlbel's answer at http://tex.stackexchange.com/a/112895/
/tikz/visible on=<\forestoption{no node before}->,
/tikz/every label/.append style={visible on=<\forestoption{no node before}->},
/tikz/every edge label/.append style={visible on=<\forestoption{no edge before}->},
edge={/tikz/visible on=<\forestoption{no edge before}->}},
show me up/.style={
before typesetting nodes={
tempcounta/.max={>O{level}}{tree},
where n children=0{
tier=terminus,
no edge before=2,
}{
tempcountb/.process={ORw2+n{level}{tempcounta}{(##2-##1)+1}},
tempcountc/.process={Rw+n{tempcountb}{##1+1}},
tier/.register=tempcountb,
math content,
no node before/.register=tempcountb,
no edge before/.register=tempcountc,
},
},
for tree={bottom up},
},
}
\begin{document}
\begin{frame}
\begin{forest}
for tree={l sep+=1em},
show me up
[ {\{m_7,m_{11}\}}
[{\{m_8,m_9\}}
[{\{m_1,m_2,m_4\}}
[{\{m_1,m_3\}}
[1][2],
]
[{\{\dots\}}
[3][4\\\plus]
]
]
[{\{m_7\}}
[ {\{m_7\}}
[{5\onslide<5->{\\\minus}}, for current and ancestors={highlight edge on=<5->}][6]
]
[ {\{\dots\}}
[7\\\plus][8\\\plus]
]
]
]
[{\{\dots\}}%,visible on=<2->
[{\{\dots\}}[9\\\minus][10]]
[{\{\dots\}}[11][12\\\minus]]
]
]
\end{forest}
\end{frame}
\end{document}