![Tikz 图形绘制节点距离](https://linux22.com/image/427468/Tikz%20%E5%9B%BE%E5%BD%A2%E7%BB%98%E5%88%B6%E8%8A%82%E7%82%B9%E8%B7%9D%E7%A6%BB.png)
我想在 Tikz 中创建具有给定节点距离的特定图形。我尝试过:
\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{graphs,graphdrawing,positioning,graphdrawing.layered}
\begin{document}
Setting the distance does not work:
\[
\begin{tikzpicture}[node distance=10pt]
\graph[nodes={draw,circle,minimum size=5pt,inner sep=0pt,as=}]
{ 1--[draw=gray]2--[draw=gray]3; 1--[bend left]3; };
\end{tikzpicture}
\]
Setting the distance works:
\[
\begin{tikzpicture}
\graph[layered layout,grow=right,level distance=10pt,nodes={draw,circle,minimum size=5pt,inner sep=0pt,as=}]
{ 1--[draw=gray]2--[draw=gray]3; };
\end{tikzpicture}
\]
Adding third edge changes layout:
\[
\begin{tikzpicture}
\graph[layered layout,grow=right,level distance=10pt,nodes={draw,circle,minimum size=5pt,inner sep=0pt,as=}]
{ 1--[draw=gray]2--[draw=gray]3; 1--[bend left]3; };
\end{tikzpicture}
\]
\end{document}
导致
基本上我想要第一个图,但具有第二个图的节点距离。所以我的问题是,如何在\graph
不指定布局(如分层布局)的情况下设置节点距离?
答案1
\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{graphs,positioning,}
\begin{document}
Setting the distance does not work:
\[
\begin{tikzpicture}
\graph[nodes={draw,circle,minimum size=5pt,inner sep=0pt,as=}]
{ 1--[draw=gray]2--[draw=gray]3; 1--[bend left]3; };
\end{tikzpicture}
\]
Setting the distance works:
\[
\begin{tikzpicture}
\graph[nodes={draw,circle,minimum size=5pt,inner sep=0pt,as=}]
{ 1--[draw=gray]2--[draw=gray]3; };
\end{tikzpicture}
\]
Adding third edge changes layout:
\[
\begin{tikzpicture}
\graph[nodes={draw,circle,minimum size=5pt,inner sep=0pt,as=}]
{ 1--[draw=gray]2--[draw=gray]3; 1--[bend left]3; };
\end{tikzpicture}
\]
\end{document}