Tikz 图形绘制节点距离

Tikz 图形绘制节点距离

我想在 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}

相关内容