我想创建一个关系代数运算符树,我已经尝试过使用森林或 tikz-tree,但问题不在于树,问题在于链接不同的运算符。我想创建这个:
但是这种图形不是树,所以对我来说很难创建它。例如,我不知道如何制作 sigma 上的叶子和 pi 上的分支,而 pi 在 sigma 下标中。我能做的最好的是使用 tiz-nodes 和关系,但看起来不太好:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\node (empates) {{$\sigma_{Empates\ \ =\ \ }$}};
\node[right=-0.2cm of empates] (pi) {{$(\pi_{Num\_Empates}$}};
\node[below= of empates] (viewA) {View A};
\node[below= of pi] (sigmatemporada) {{$\sigma_{A.temporada=t}$}};
\node[below= of sigmatemporada] (f) {{$f_{MAX(EMPATES)}$}};
\draw (empates) -- (viewA);
\draw (pi) -- (sigmatemporada);
\draw (sigmatemporada) -- (f);
\end{tikzpicture}
\end{document}
答案1
您可以将\sigma
等\pi
放在单独的节点中。但要注意正确对齐:
\documentclass[border=5mm]{standalone}
\usepackage{tikz,amsmath}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[every node/.append style={inner sep=0pt, font=\vphantom{$f_p$}},
every path/.append style={shorten >=2.5pt, shorten <=2.5pt}]
\node (s1) {$\sigma$};
\node[right=-1pt of s1] (e1) {$_{Empates}$};
\node[below of=s1] (v1) {View A};
\node[right=15mm of s1] {$= \quad ($};
\node[right=25mm of s1] (p1) {$\pi$};
\node[right=-1pt of p1] (e2) {$_{Num\_Empates}$};
\node[below of=p1] (s2) {$\sigma$};
\node[right=-1pt of s2] (t1) {$_{A.Temporada \, = \, t}$};
\node[below of=s2] (f) {$f$};
\node[right=-1pt of f] (m1) {$_{\max(Empates)\, Num\_Empates}$};
\node[left=-1pt of f] (m2) {$\genfrac{}{}{0pt}{}{temporada}{t}$};
\node[below of=f] (v2) {View};
\node[right=2mm of v2] {$)$};
\draw (s1) -- (v1);
\draw (s2) -- (p1);
\draw (p1) -- (s2);
\draw (s2) -- (f);
\draw (f) -- (v2);
\end{tikzpicture}
\end{document}