下面的 MWE 生成了一个简单的图。当我将两个上部节点 A1 和 B1 添加到子图中时,水平对齐会丢失,这是可以理解的,因为子图中的节点独立于其他节点定位。我不明白的是,从 B1 到 B3 的连接不再是直线了。我该如何在保留子图的同时修复这个问题?
注意:我需要在更复杂的示例中使用子图,在那里我会遇到同样的问题。
\documentclass[border=0.125cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{graphdrawing}
\usetikzlibrary{graphs,quotes}
\usegdlibrary{trees,layered,force}
\begin{document}
\tikz \graph[layered layout] {
"A1";
"B1";
"B3";
"A2";
"A3";
"C";
"A2" -- "A3";
"A3" -- "C";
"B1" --[minimum layers=2] "B3";
"A1" -- "A2";
"B3" -- "C";
};
\tikz \graph[layered layout] {
//[layered layout]{
"A1";
"B1";
};
"B3";
"A2";
"A3";
"C";
"A2" -- "A3";
"A3" -- "C";
"B1" --[minimum layers=2] "B3";
"A1" -- "A2";
"B3" -- "C";
};
\end{document}
答案1
后期的解决方法:bend left=0
针对该边或所有边设置:
%! TEX program = lualatex
\RequirePackage{luatex85}
\documentclass[border=0.125cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{graphdrawing}
\usetikzlibrary{graphs,quotes}
\usegdlibrary{trees,layered,force}
\begin{document}
\tikz \graph[layered layout] {
"A1";
"B1";
"B3";
"A2";
"A3";
"C";
"A2" -- "A3";
"A3" -- "C";
"B1" --[minimum layers=2] "B3";
"A1" -- "A2";
"B3" -- "C";
};
\tikz \graph[layered layout,edges={bend left=0}] {
//[layered layout]{
"A1";
"B1";
};
"B3";
"A2";
"A3";
"C";
"A2" -- "A3";
"A3" -- "C";
"B1" --[minimum layers=2, bend left=0] "B3";
"A1" -- "A2";
"B3" -- "C";
};
\end{document}