如图,如何简单实现?用child太麻烦了。用tree我不会列结果的坐标形式和小红小明那种。刚学几天,用实例改的,还不怎么懂,请各位大神指教。代码如下:
\documentclass[UTF8]{ctexart}
%\usepackage{amsmath}
%\usepackage{graphicx}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[every node/.style={inner sep=5pt},edge from parent/.style={draw,->,red,very thick},level 1/.style={sibling distance=25mm},
level 2/.style={sibling distance=5mm}] % 为所有分支设置层间距
\node {开始} [grow'=right]
child {node[yshift=-15mm]{小红} edge from parent[draw=none]}
child {node {A}
child {node{小明} edge from parent[draw=none] child {node[xshift=1mm] {结果}}}
child {node {A} child {node {(A,A)}}}
child {node {B} child {node {(A,B)}}}
child {node {C} child {node {(A,C)}}}
child {node {D} child {node {(A,D)}}}
}
child {node {B}
child {node {A}}
child {node {B}}
child {node {C}}
child {node {D}}
}
child {node {C}
child {node {A}}
child {node {B}}
child {node {C}}
child {node {D}}
}
child {node {D}
child {node {A}}
child {node {B}}
child {node {C}}
child {node {D}}
};
\end{tikzpicture}
\end{document}
\documentclass[UTF8]{ctexart}
\usepackage{tikz}
\usetikzlibrary{graphs,graphdrawing,arrows,graphs.standard}
\usegdlibrary{trees,layered}
\begin{document}
\tikz \graph [tree layout,grow'=right,level distance=2.5cm,sibling distance=1mm,sibling sep=2pt
,nodes={red,inner sep=5pt,minimum size=5mm}] { { [number nodes, number nodes sep=*]
开始->[red] {
A -> {A--这里写结果,B,C,D},
B -> {A,B,C,D},
C -> {A,B,C,D},
D-> {A,B,C,D}, } },
};
\end{document}
\begin{tikzpicture}
\graph [
tree layout,
grow'=right,
level distance=2.5cm,
sibling distance=1mm,
sibling sep=2pt,
nodes={red,inner sep=5pt,minimum size=5mm}
]
{[number nodes, number nodes sep=*]
开始-> {
A-> {A->Ac/"(A,A)",
B,C,D},
B -> {A,B,C,D},
C -> {A,B,C,D},
D-> {A,B,C,D},
小王[>{draw=none}]--小李[>{draw=none}]->那啥,
},
};
\node [above]at(A*2 |- A*3.north){小红};
\node [above](小明)at(A*3.north){小明};
\node [above](结果)at(Ac*4 |- A*3.north){结果};
\draw [->](小明)--(结果);
\end{tikzpicture}
——————————————————————————————————————
补充,参考选项 /tikz/graph/parse
\def\mystateA{}
\foreach \i[count=\ci,remember=\i as \li] in {A,B,C,D}
{
\ifnum\ci=1\relax
\else
\xdef\mystateA{\mystateA\li->{\mystateB},}
\fi
\xdef\mystateB{}
\foreach \j[count=\cj] in {A,B,C,D}
{
\xdef\mystateB{\mystateB\j->\i\j/"(\i,\j)",}
\ifnum\ci=4\relax
\ifnum\cj=4\relax
\xdef\mystateA{\mystateA\i->{\mystateB},}
\fi
\fi
}
}
\begin{tikzpicture}
\graph [
tree layout,
grow'=right,
level distance=2.5cm,
sibling distance=1mm,
sibling sep=2pt,
nodes={red,inner sep=5pt,minimum size=5mm}
]
{
[number nodes, number nodes sep=*]
开始-> {
[parse/.expanded=\mystateA]
},
};
\node (结果)[above] at(AA*4.north){结果};
\node (小明)[above] at(A*3.north |- AA*4.north){小明};
\node (小红)[above] at(A*2.north |- AA*4.north){小红};
\end{tikzpicture}
感谢大神。结果列是根据小红与小明的组合写成坐标形式,能不能实现自动获取小红和小明数据来写结果列呢?`begin{tikzpicture}
end{tikzpicture}`
{{image.png(uploading...)}}
@u44130
如果树的规模较小,就像上面的例子,建议手工写代码。如果树较大,可以参考手册中关于
的例子。