为什么我的 Lualatex 找不到 spring 布局

为什么我的 Lualatex 找不到 spring 布局

我正在尝试绘制弹簧布局图,但出现错误,提示弹簧布局未知。PS 我使用所有其他布局,例如项链。我的代码可能出了什么问题:

\documentclass{article}

\usepackage{geometry}
 \geometry{
 a4paper,
 total={210mm,297mm},
 left=5mm,
 right=5mm,
 top=20mm,
 bottom=20mm,
 }
\usepackage{tikz}
\usetikzlibrary{quotes}
\usetikzlibrary{shapes}
\usetikzlibrary{graphdrawing}
\usetikzlibrary{graphs}
\usegdlibrary{trees}
\usegdlibrary{circular}
\definecolor{burntorange}{cmyk}{0,0.52,1,0}
\definecolor{violet}{cmyk}{0.79,0.88,0,0}
\def\oran{orange!30}
\tikzstyle{vertex}=[draw,circle,burntorange, left color=\oran,text=violet,minimum width=20pt]
\begin{document}


\begin{tikzpicture}[spring layout, node distance=50pt]
\node (0) [vertex] {0};
\node (1) [vertex] {1};
\node (2) [vertex] {2};
\node (3) [vertex] {3};
\node (4) [vertex] {4};
\node (5) [vertex] {5};
\node (6) [vertex] {6};
\node (7) [vertex] {7};
\node (8) [vertex] {8};
\node (9) [vertex] {9};
\path (0) edge[--] (1); 
\path (0) edge[--] (2); 
\path (0) edge[--] (3); 
\path (1) edge[--] (4); 
\path (3) edge[--] (5); 
\path (3) edge[--] (6); 
\path (2) edge[--] (7); 
\path (7) edge[--] (8); 
\path (5) edge[--] (9); 
\end{tikzpicture}

\end{document}

提前致谢。

答案1

spring layout是图书馆的一部分force。因此您必须添加\usegdlibrary{force}

\documentclass{article}

\usepackage{geometry}
 \geometry{
 a4paper,
 total={210mm,297mm},
 left=5mm,
 right=5mm,
 top=20mm,
 bottom=20mm,
 }
\usepackage{tikz}
\usetikzlibrary{quotes}
\usetikzlibrary{shapes}
\usetikzlibrary{graphdrawing}
\usetikzlibrary{graphs}
\usegdlibrary{trees}
\usegdlibrary{circular}
\usegdlibrary{force} % <-- ADD LIBRARY !!!
\definecolor{burntorange}{cmyk}{0,0.52,1,0}
\definecolor{violet}{cmyk}{0.79,0.88,0,0}
\def\oran{orange!30}
\tikzstyle{vertex}=[draw,circle,burntorange, left color=\oran,text=violet,minimum width=20pt]
\begin{document}


\begin{tikzpicture}[spring layout, node distance=50pt]
\node (0) [vertex] {0};
\node (1) [vertex] {1};
\node (2) [vertex] {2};
\node (3) [vertex] {3};
\node (4) [vertex] {4};
\node (5) [vertex] {5};
\node (6) [vertex] {6};
\node (7) [vertex] {7};
\node (8) [vertex] {8};
\node (9) [vertex] {9};
\path (0) edge[--] (1); 
\path (0) edge[--] (2); 
\path (0) edge[--] (3); 
\path (1) edge[--] (4); 
\path (3) edge[--] (5); 
\path (3) edge[--] (6); 
\path (2) edge[--] (7); 
\path (7) edge[--] (8); 
\path (5) edge[--] (9); 
\end{tikzpicture}

\end{document}

输出:

力量


默认值为inner sep.3333em有关更多信息,请参阅手册第 17.2.3 节。通常这看起来很不错,但在你的情况下,如果你在节点中输入较大的数字,它会使节点不成比例地大。因此,你要做的是删除内部分离并仅使用 来控制节点的大小minimum width

\tikzstyle{vertex}=[draw,circle,burntorange, left color=\oran,text=violet, inner sep=0, minimum width=20pt]

输出:

force_2

相关内容