我想尝试将此图表包含在提供的 Beamer 中,并希望使用 TikZ 绘制它,而不是包含 PDF(出于多种原因)。老实说,我不知道如何开始,当我尝试查看 tkz-graph 库时,所有文档都是法语的。我不一定一心想使用该软件包,但如果没有别的,我希望得到一些关于如何处理这个问题的提示。我还尝试根据这个例子找到解决方案:texample.net 示例图但根本无法编译。我知道没有 MWE,但老实说,我真的不知道该如何处理。
我刚刚看到了回复,但我尝试了以下几句话:
\documentclass[10pt,tikz]{standalone}
\usepackage[sfdefault]{FiraSans}
\usetikzlibrary{arrows,shapes,positioning}
\begin{document}
\begin{tikzpicture}[
thick,
>=stealth',
shorten >=1pt,
auto,
every node/.style={
rectangle,
rounded corners,
draw}
]
\node (1) {Aristotle};
\node (2) [right = of 1] {Chrisyppus};
\node (3) [below right = of 1] {Leibniz};
\node (4) [below left = of 1] {Boole};
\node (5) [below = of 4] {Frege};
\node (6) [right = of 5] {Tarski};
\node (7) [below right = of 3] {Post};
\node (8) [below = of 6] {McCarthy};
\node (9) [left = of 8] {Minski};
\node (10) [right = of 8] {Kowalski};
\node (11) [below = of 7] {Colmerauer};
\node (12) [below left = of 8] {McDermott};
\node (13) [right = 0.25cm of 12] {Reiter};
\node (14) [below right = of 8] {Moore};
\node (15) [below = 2cm of 8] {Gelfond};
\node (16) [below = of 11] {Prolog};
\node (17) [below = of 16] {Clark};
\node (18) [below = of 15] {A-Prolog};
\path[->]
(1) edge (3)
(2) edge (3)
(4) edge (5)
(5) edge (6)
(6) edge (8)
(6) edge (9)
(3) edge (10)
(6) edge (10)
(7) edge (10)
(7) edge (11)
(8) edge (12)
(8) edge (13)
(8) edge (14)
(8) edge (15)
(8) edge (14)
(14) edge (15)
(11) edge (16)
(10) edge (16)
(16) edge (17)
(17) edge (15)
(15) edge (18)
;
\end{tikzpicture}
\end{document}
这给出了与可接受答案类似但更复杂的答案。我很好奇是否有关于如何定位以正确对齐节点的指导(或者是否有节点的“自动定位”库)。
答案1
作为起点,您可以使用:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}\small
\begin{tikzpicture}[node distance=20mm,every node/.style={rectangle,minimum height=10mm,text width=17mm,align=center,rounded corners=1mm,fill=green!50!black,draw=black}]
\node at (0,0) (ko) {Kowalski};
\node[above of=ko,node distance=40mm]
(le) {Leibniz};
\node[above of=le,xshift=10mm] (ar) {Aristotle};
\node[left of=ar] (ch) {Chrisyppus};
\node[right of=ko] (co) {Colmerauer};
\node[above of=co] (po) {Post};
\node[left of=ko] (mc) {McCarthy};
\node[above of=mc] (ta) {Tarski};
\node[left of=mc] (mi) {Minski};
\node[left of=ta,node distance=30mm]
(fr) {Frege};
\node[above of=fr] (bo) {Boole};
\node[below of=co,xshift=-5mm,fill=blue!75!cyan]
(pr) {Prolog};
\node[below of=pr] (cl) {Clark};
\node[below of=mc,xshift=12mm]
(mo) {Moore};
\node[below of=mc,xshift=-12mm]
(re) {Reiter};
\node[left of=re]
(do) {McDermott Doyle};
\node[below of=mc,node distance=40mm]
(ge) {Gelfond Lifschitz};
\node[below of=ge,fill=blue!75!cyan]
(ap) {A-Prolog};
\foreach \x/\y in {ar/le,ch/le,le/ko,po/ko,po/co,bo/fr,fr/ta,ta/mi,ta/mc,ta/ko,mc/do,mc/re,mc/mo,mc/ge,mo/ge,ko/pr,co/pr,pr/cl,pr/ge,cl/ge,ge/ap}
\draw[-stealth,shorten >=1mm] (\x) -- (\y);
\end{tikzpicture}
\end{document}
答案2
这解决方案使用\tikz \graph
,即故意将确切的放置委托给算法,有点懒惰,允许使用类似而不是相同的图表(体现“少做一点”的创新原则)。
这结果稍微调整了一下,使其看起来更美观,故意留下一些视觉上的“凸起”或信息,比如节点大小和名称长度之间的关系(体现“不对称”的发明原理)。
基本思想:
将节点的放置(之前完成
\graph
)与用箭头连接节点(使用内部指定的链\graph
)分开从所有其他节点开始,
node Aristotle
相对于此节点定位A
dummy-node (du)
被用来node Post
稍微移动,后来通过填充白色变得“看不见”;可能有更好的方法来实现Node Kowalsky
放置在假人右下方时位置更佳颜色
Prolog-nodes
不同style bln
该
\graph
部分仅使用对上述节点的引用来指示哪些节点或节点集应该在视觉上连接;根据需要引入箭头弯曲\documentclass[10pt]{standalone} \usepackage{tikz} \usetikzlibrary{graphdrawing, graphs, positioning} \begin{document} \tikz [ draw, align=center,%multiline text seems to need alignment bln/.style={fill=blue!30},% for the blue nodes every node/.style={fill=green!30, rounded corners}%default style ] { % relative positioning, "row" by "row" \node (ar) {Arisotle}; \node (ch) [right=of ar] {Chrisyppus}; \node (le) [below=of ar] {Leibniz}; \node (bo) [left=of le] {Boole}; \node (fr) [below=of bo] {Frege}; \node (ta) [right=of fr] {Tarski}; \node (du) [right=of ta, fill=white] {};% a dummy node \node (po) [right=of du] {Post}; \node (mc) [below=of ta] {McCarthy}; \node (ko) [below right=of du] {Kowalski};% nicer placement \node (mi) [left=of mc] {Minski}; \node (co) [right=of ko] {Colmerauer}; \node (pr) [below=of ko, bln] {Prolog};% blue node \node (mo) [below=of mc] {Moore}; \node (re) [left=of mo] {Reiter}; \node (md) [left=of re] {McDermott\\Doyle}; \node (cl) [below=of pr] {Clark}; \node (ge) [left=of cl] {Gelfond\\Lifschitz}; \node (ap) [below=of ge, bln] {A-Prolog};% blue node \graph{ {(ar), (ch)} -> (le);% referencing aboves nodes via () (bo) -> (fr) -> (ta); (le) -> (ko); (ta) -> {(mi), (mc), (ko)};% one source, three targets (po) -> {(ko), (co)}; {(ko), (co)} -> (pr); (mc) -> {(md), (re), (mo)}; {(mc), (mo), (pr)} -> (ge); (pr) -> (cl) -> (ge); (ge) -> (ap); }; } \end{document}