我想链接 subA->subB,其中 subA 和 subB 的所有组件完全相同。当我绘制它时,两个子图相互重叠。有什么想法吗?
\documentclass{article}
% \usepackage{caption}
\usepackage{subcaption}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usetikzlibrary {graphs, graphdrawing, positioning}
\usetikzlibrary{automata,arrows,positioning,calc}
\usegdlibrary {layered,force, circular, trees}
\begin{document}
\begin{tikzpicture}[>=stealth, auto]
\graph [layered layout, sibling distance=15mm, grow'=right] {
subA [draw, circle] // [tree layout] {a -> {1,2};};
subB [draw, circle] // [tree layout] {a -> {1,2};};
subA -> subB
};
\end{tikzpicture}
\end{document}
这是我得到的:
但我需要分离 subA 和 subB 并将它们的节点保留为 {a, 1, 2},是的,它们的节点完全相同
答案1
这是你想要的吗?
注意fresh nodes
钥匙您也可以只将其提供给子布局。
代码
\documentclass[tikz]{standalone}
\usetikzlibrary{graphs, graphdrawing}
\usegdlibrary {layered, trees}
\begin{document}
\begin{tikzpicture}[>=stealth, auto]
\graph [layered layout, sibling distance=15mm, grow'=right, fresh nodes] {
subA [draw, circle] // [tree layout] {a -> {1, 2};};
subB [draw, circle] // [tree layout] {a -> {1, 2};};
subA -> subB
};
\end{tikzpicture}
\end{document}
输出
如果你发现自己需要重复使用一个特定的子图,你可以使用declare
钥匙。在本节的最后,手册还为您的问题提供了另一种解决方案,name
即将其值作为名称前缀的键。
代码
\documentclass[tikz]{standalone}
\usetikzlibrary{graphs, graphdrawing}
\usegdlibrary {layered, trees}
\begin{document}
\tikz[>=stealth, auto]
\graph [
layered layout, sibling distance=15mm, grow'=right,
declare={myGraph}{a -> {1, 2}}
] {
subA [draw, circle] // [tree layout] { myGraph[name=subA] };
subB [draw, circle] // [tree layout] { myGraph[name=subB] };
subA -> subB;
subA a <->[red] subB 1;
};
\end{document}