我使用 Ovearleaf,由于以下 TikZ 图片它让我超时:
\begin{tikzpicture}[font=\footnotesize,scale=1.4]
\tikzset{
solid node/.style={circle,draw,inner sep=1.5,fill=black},
hollow node /.style={circle,draw,inner sep=1.5}
}
\tikzstyle{level 1}=[level distance=12mm, sibling distance = 25 mm]
\tikzstyle{level 2}=[level distance=15mm, sibling distance = 15 mm]
\tikzstyle{level 3}=[level distance=17mm, sibling distance = 10 mm]
\node(0)[solid node,label=right:{Naturaleza}]{}
child[grow=up]{node[solid node, label=above:{$F_B$}]{}
child[grow=left]{node(1)[solid node, label below:{}]{}
child{node[hollow node, label=left:{$(1;1)$}]{} edge from parent node [above]{$c$}}
child{node[hollow node, label=left:{$(2;0)$}]{} edge from parent node [below]{$nc$}}
edge from parent node [above]{$cert$}
}
child[grow=right]{node(2)[solid node, label below:{}]{}
child{node[hollow node, label=left:{$(0;0)$}]{} edge from parent node [above]{$c$}}
child{node[hollow node, label=left:{$(2;0)$}]{} edge from parent node [below]{$nc$}}
edge from parent node [above]{$Ncert$}
}
edge from parent node[right]{$0,5$}
}
child[grow=down]{node[solid node, label=below:{$F_M$}]{}
child[grow=left]{node(2)[solid node, label=above:{}]{}
child{node[hollow node, label=left:{$(0;0)$}]{} edge from parent node [above]{$c$}}
child{node[hollow node, label=left:{$(2;0)$}]{} edge from parent node [below]{$nc$}}
edge from parent node [above]{$cert$}
}
child[grow=left]{node(4)[solid node, label=above:{}]{}
child{node[hollow node, label=right:{$(0;0)$}]{} edge from parent node [above]{$c$}}
child{node[hollow node, label=right:{$(2;0)$}]{} edge from parent node [below]{$nc$}}
edge from parent node [above]{$Ncert$}
}
edge from parent node[right]{$0,5$}
}
\draw[dashed, rounded corners=10]($(1)+(-.45,.45)$)rectangle($(2)+(.45,-.45)$);
\draw[dashed, rounded corners=10]($(3)+(-.45,.45)$)rectangle($(2)+(.45,-.45)$);
\node at ($(1)!5!(2)$){Consumidor}
\node at ($(3)!5!(4)$){Consumidor}
\end{tikzpicture}
答案1
我做的改变:
- 添加
\documentclass{article}
和document
环境。加载tikz
包及其calc
库。 - 在所有三个命令末尾添加缺失的分号
\node
。 - 改成。
hollow node /.style
hollow node/.style
- 将两个
label below:{}
改为label=below:{}
。 - 调整代码缩进,无功能。
现在它几乎可以编译,除了未知的节点名称3
。
PS:大节点树是\node {} {child {node{}} child {node{}} ...};
由某个程序生成的吗?如果是,程序的名字是什么?
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[font=\footnotesize,scale=1.4]
\tikzset{
solid node/.style={circle,draw,inner sep=1.5,fill=black},
hollow node/.style={circle,draw,inner sep=1.5}
}
\tikzstyle{level 1}=[level distance=12mm, sibling distance = 25 mm]
\tikzstyle{level 2}=[level distance=15mm, sibling distance = 15 mm]
\tikzstyle{level 3}=[level distance=17mm, sibling distance = 10 mm]
\node(0)[solid node,label=right:{Naturaleza}]{}
child[grow=up]{
node[solid node, label=above:{$F_B$}]{}
child[grow=left]{
node(1)[solid node, label=below:{}]{}
child{node[hollow node, label=left:{$(1;1)$}]{}
edge from parent node [above]{$c$}}
child{node[hollow node, label=left:{$(2;0)$}]{}
edge from parent node [below]{$nc$}}
edge from parent node [above]{$cert$}
}
child[grow=right]{
node(2)[solid node, label=below:{}]{}
child{
node[hollow node, label=left:{$(0;0)$}]{}
edge from parent node [above]{$c$}
}
child{
node[hollow node, label=left:{$(2;0)$}]{}
edge from parent node [below]{$nc$}
}
edge from parent node [above]{$Ncert$}
}
edge from parent node[right]{$0,5$}
}
child[grow=down]{
node[solid node, label=below:{$F_M$}]{}
child[grow=left]{node(2)[solid node, label=above:{}]{}
child{
node[hollow node, label=left:{$(0;0)$}]{}
edge from parent node [above]{$c$}
}
child{
node[hollow node, label=left:{$(2;0)$}]{}
edge from parent node [below]{$nc$}}
edge from parent node [above]{$cert$}
}
child[grow=left]{
node(4)[solid node, label=above:{}]{}
child{
node[hollow node, label=right:{$(0;0)$}]{}
edge from parent node [above]{$c$}
}
child{
node[hollow node, label=right:{$(2;0)$}]{}
edge from parent node [below]{$nc$}
}
edge from parent node [above]{$Ncert$}
}
edge from parent node[right]{$0,5$}
};
\draw[dashed, rounded corners=10]($(1)+(-.45,.45)$)rectangle($(2)+(.45,-.45)$);
\draw[dashed, rounded corners=10]($(3)+(-.45,.45)$)rectangle($(2)+(.45,-.45)$);
\node at ($(1)!5!(2)$){Consumidor};
\node at ($(3)!5!(4)$){Consumidor};
\end{tikzpicture}
\end{document}
答案2
- 您的 MWE 中的大部分错误都列在@muzimuzhi Z 的回答中
- 我必须承认,我迷失在你的子节点“森林”中,因此可能发生以下 MWE 中的某些标签是错误的或位于错误的位置的情况
- 我的估计是,不使用语法来绘制图像的代码
tree
更简单,而且(更)清晰:
\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,
fit,
positioning,
quotes}
\begin{document}
\begin{tikzpicture}[
node distance = 8mm and 24mm,
FIT/.style = {draw, dashed, rounded corners, inner sep=5mm,
fit=#1, node contents={}},
dot/.style = {circle, inner sep=1.5, label=#1,
node contents={}},
hdot/.style = {dot=#1, draw},
sdot/.style = {dot=#1, draw, fill},
every label/.style = {font=\footnotesize, inner sep=2pt},
every edge quotes/.style = {auto, font=\footnotesize,
inner sep=2pt, sloped}
]
\node (n1a) [hdot=left:{(1;1)}];
\node (n2) [sdot=, below right=of n1a];
\node (n3) [sdot=above:$F_B$, right=of n2];
\node (n4) [sdot={}, right=of n3];
\node (n5a) [sdot=right:{(2;0)}, above right=of n4];
\node (n1b) [hdot=left:{(2;0)},
below left=of n2];
\node (n5b) [sdot=right:{(0;0)}, below right=of n4];
%
\node (n6) [sdot=right:Naturaleza, below=of n1b -| n3];
%
\node (n7a) [hdot=left:{(0;0)}, below=of n1b |- n6];
\node (n8) [sdot=, below right=of n7a];
\node (n9) [sdot=below:$F_M$, right=of n8];
\node (n7b) [hdot=left:{(2;0)}, below left =of n8];
%%%% arrows
\draw (n1a) edge ["$c$"] (n2)
(n1b) edge ["$nc$" '] (n2)
(n2) edge ["$cert$"] (n3)
(n3) edge ["$Ncert$"] (n4)
(n4) edge ["$nc$"] (n5a)
(n4) edge ["$c$" '] (n5b)
%
(n3) edge ["{$0,5$}" sloped=false] (n6)
(n6) edge ["{$0,5$}" sloped=false] (n9)
%
(n7a) edge ["$c$"] (n8)
(n7b) edge ["$nc$" '] (n8)
(n8) edge ["$Ncert$"] (n9)
;
%%%% dashed boxes
\node [FIT=(n2) (n8)];
\node (aux1) [dot=, left=11mm of n6];
\node (aux2) [dot=, left=11mm of n9];
\node [FIT=(aux1) (aux2)];
\end{tikzpicture}
\end{document}