我是 tikz-qtree 包的新手/初学者,正在尝试从 R 下的 F 到 T(级别 2)绘制直线。另一个问题是,使用命令 \only{...} 并不容易,如何以更好的方式使用 \only{...}。
\documentclass{beamer}
\usepackage{tikz-qtree}
\begin{document}
\begin{frame}
\begin{tikzpicture}[level distance=1.5cm, sibling distance=0.5cm]
\tikzset{grow'=up,frontier/.style={distance from root=150pt}}
\only<1>{
\Tree [.\mbox{ } \edge[draw=none];
[.\mbox{ } \edge[draw=none]; [.\mbox{ } \edge[draw=none]; [.$T$
\edge[draw=none]; $(P$ ] \edge[draw=none]; [.\mbox{ } \edge[draw=none];
$\wedge$ ] \edge[draw=none]; [.$T$ \edge[draw=none]; $Q)$ ] ]
\edge[draw=none]; $\vee$ \edge[draw=none]; [ \edge[draw=none]; [.$F$
\edge[draw=none]; $R$ ] ] ]
\edge[draw=none]; [.\mbox{ } \edge[draw=none]; $\leftrightarrow$ ]
\edge[draw=none]; [.\mbox{ } \edge[draw=none]; [.\mbox{ }
\edge[draw=none]; [.$\sim F$ \edge[draw=none]; $(\sim R$ ] ]
\edge[draw=none]; [.\mbox{ } \edge[draw=none]; [.\mbox{ }
\edge[draw=none]; $\wedge$ ] ] \edge[draw=none]; [.\mbox{ }
\edge[draw=none]; [.$\sim T$ \edge[draw=none]; $\sim Q)$ ] ] ]
]
}
\only<2>{
\Tree [.\mbox{ } \edge[draw=none];
[.\mbox{ } \edge[draw=none]; [.$T$ [.$T$ \edge[draw=none]; $(P$ ]
\edge[draw=none]; [.\mbox{ } \edge[draw=none]; $\wedge$ ] [.$T$
\edge[draw=none]; $Q)$ ] ] \edge[draw=none]; $\vee$ \edge[draw=none]; [
\edge[draw=none]; [.$F$ \edge[draw=none]; $R$ ] ] ]
\edge[draw=none]; [.\mbox{ } \edge[draw=none]; $\leftrightarrow$ ]
\edge[draw=none]; [.\mbox{ } \edge[draw=none]; [.$T$ [.$\sim F$
\edge[draw=none]; $(\sim R$ ] ] \edge[draw=none]; [.\mbox{ }
\edge[draw=none]; [.\mbox{ } \edge[draw=none]; $\wedge$ ] ]
\edge[draw=none]; [.$F$ [.$\sim T$ \edge[draw=none]; $\sim Q)$ ] ] ]
]
}
\only<3>{
\Tree [.\mbox{ } \edge[draw=none];
[.$T$ [.$T$ [.$T$ \edge[draw=none]; $(P$ ] \edge[draw=none]; [.\mbox{ }
\edge[draw=none]; $\wedge$ ] [.$T$ \edge[draw=none]; $Q)$ ] ]
\edge[draw=none]; $\vee$ [ [.$F$ \edge[draw=none]; $R$ ] ] ]
\edge[draw=none]; [.\mbox{ } \edge[draw=none]; $\leftrightarrow$ ]
\edge[draw=none]; [.$F$ [.$T$ [.$\sim F$ \edge[draw=none]; $(\sim R$ ] ]
\edge[draw=none]; [.\mbox{ } \edge[draw=none]; [.\mbox{ }
\edge[draw=none]; $\wedge$ ] ] [.$F$ [.$\sim T$ \edge[draw=none]; $\sim Q)$ ] ] ]
]
}
\only<4>{
\Tree [.\alert{$F$}
[.$T$ [.$T$ [.$T$ \edge[draw=none]; $(P$ ] \edge[draw=none]; [.\mbox{ }
\edge[draw=none]; $\wedge$ ] [.$T$ \edge[draw=none]; $Q)$ ] ]
\edge[draw=none]; $\vee$ [ [.$F$ \edge[draw=none]; $R$ ] ] ]
\edge[draw=none]; [.\mbox{ } \edge[draw=none]; $\leftrightarrow$ ]
[.$F$ [.$T$ [.$\sim F$ \edge[draw=none]; $(\sim R$ ] ]
\edge[draw=none]; [.\mbox{ } \edge[draw=none]; [.\mbox{ }
\edge[draw=none]; $\wedge$ ] ] [.$F$ [.$\sim T$ \edge[draw=none]; $\sim Q)$ ] ] ]
]
}
\end{tikzpicture}
\end{frame}
\end{document}
答案1
如果 Forest 是一个选项,您可以自动化增量发现,改进对齐并简化指定树所需的代码。
森林是专业的 Ti钾基于 Z 的绘制树的包。下面的一些代码具有杰出的血统,并且代码被相应地注释以归因于(我希望)所有涉及的人员。(如果我遗漏了某人,请告诉我!)
我定义了一种特殊的森林风格semantic tree
来绘制问题中的那种树。
所有节点都以数学模式排版,但最后一级(即句子下方)以上的节点用 包裹,
\text{}
以便T
/F
直立。因此,$...$
此处必须使用 来表示否定。树会自动逐渐呈现,每张幻灯片一行,如问题所示。由于这根本不需要树规范中的任何额外内容,我认为这是一个足够简单的方法 ;)。
此外,
我使用
\tnot
来表示波浪号not
,以纠正间距。(TeX 假设该符号表示二元关系,这是不正确的。)\ob
并\cb
排版开括号和闭括号,而不会影响后面或前面内容的对齐。connective=<connective>
在当前节点的右侧添加一个包含连接词的节点。direct connect to=<node>
在当前节点和指定节点之间建立直接连接,而不是遵循通常的路径。
文档序言相当广泛,但好处是树本身可以非常简单和简洁地指定。
\begin{frame}
\centering
\begin{forest}
semantic tree
[F
[T
[T
[T
[\ob P, connective=\land]
]
[T
[Q\cb, connective=\lor]
]
]
[
[F, direct connect to=!uu
[R, connective=\leftrightarrow]
]
]
]
[F
[T
[$\tnot$F
[\ob\tnot R, connective=\land]
]
]
[F
[$\tnot$T
[\tnot Q\cb]
]
]
]
]
\end{forest}
\end{frame}
结果是 5 张幻灯片。
完整代码:
\documentclass{beamer}
\usepackage{forest}
\usepackage{amsmath}
\makeatletter
\tikzset{% set up for transitions using tikz with beamer overlays - developed by Daniel (http://tex.stackexchange.com/a/55849/) and, in ear lier form, by Matthew Leingang (http://tex.stackexchange.com/a/6155/) and modified for this use, I think by Qrrbrbirlbel (http://tex.stackexchange.com/a/112471/)
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
},
transparent/.style={opacity=0.1,text opacity=0.1},
opaque on/.style={alt=#1{}{transparent}},
alerted/.style={color=alerttextdefaultfg},
alert on/.style={alt=#1{alerted}{}},
}
\makeatother
\newcommand*{\tnot}{\ensuremath{\mathord{\sim}}}
\newcommand*\ob{\llap{(}}
\newcommand*\cb{\rlap{)}}
\forestset{%
semantic tree/.style={%
for tree={%
math content,
tier/.wrap pgfmath arg={tier ##1}{level()},
parent anchor=children,
child anchor=parent,
grow'=90,
},
delay={%
where level=0{%
red,
}{},
where content={}{%
coordinate,
}{},
where n children=0{%
calign with current,
}{%
content/.wrap value=\text{##1},
},
},
before packing={%
where n children=0{%
tier=terminus,
no edge,
}{},
},
before computing xy={%
where n children=0{%
l'-=10pt,
}{},
},
before typesetting nodes={%
for tree={%
for current and ancestors/.wrap pgfmath arg={%
visible from=##1,
}{int(5-(level()))},
},
},
},
connective/.style={%
before typesetting nodes={%
insert after={[#1, math content]},
},
},
direct connect to/.style={%
edge path'=(#1.parent anchor) -- (.child anchor),
tempcounta/.pgfmath=id("#1"),
for nodewalk={%
fake=parent,
while={id()!=(tempcounta)}{current,fake=parent},
}{%
no edge,
},
},
visible on/.style={% developed by Qrrbrbirlbel (http://tex.stackexchange.com/a/112471/)
for tree={%
/tikz/visible on={#1},
edge={/tikz/visible on={#1}}}},
opaque on/.style={%
for tree={%
/tikz/opaque on={#1},
edge={/tikz/opaque on={#1}}}},
alerted on/.style={%
for tree={%
/tikz/alerted on={#1},
edge={/tikz/alerted on={#1}}}},
visible from/.style={% based on Qrrbrbirlbel's answer at http://tex.stackexchange.com/a/112895/
/tikz/visible on=<#1->,
/tikz/every label/.append style={visible on=<#1->},
for children={%
/tikz/every edge label/.append style={visible on=<#1->},
edge={/tikz/visible on=<#1->},
},
},
}
\begin{document}
\begin{frame}
\centering
\begin{forest}
semantic tree
[F
[T
[T
[T
[\ob P, connective=\land]
]
[T
[Q\cb, connective=\lor]
]
]
[
[F, direct connect to=!uu
[R, connective=\leftrightarrow]
]
]
]
[F
[T
[$\tnot$F
[\ob\tnot R, connective=\land]
]
]
[F
[$\tnot$T
[\tnot Q\cb]
]
]
]
]
\end{forest}
\end{frame}
\end{document}