如何定义节点之间的默认垂直距离?

如何定义节点之间的默认垂直距离?

使用positioning可以控制节点的单独垂直位置。但是有没有什么方法可以控制默认的垂直间距呢?

\documentclass{文章}
\usepackage[utf8]{输入框}
\usepackage{tikz}
\usetikzlibrary{形状,箭头,定位}

\开始{文档}
\pagestyle{空}

\tikzstyle{decision} = [diamond, draw, 文本宽度=4.5em, 文本居中严重, 节点距离=3.5cm, 内部分离=0pt]
\tikzstyle{block} = [矩形,绘制,文本宽度=6em,文本居中,圆角,最小高度=4em,节点距离=3.5cm,最小高度=2em]
\tikzstyle{cloud} = [绘制,椭圆,节点距离=3.5cm,最小高度=2em]
\tikzstyle{线} = [绘制,-latex']

\begin{tikzpicture}[节点距离 = 1cm,自动]
  \node [块] (第 1 个) {第 1 个};
  \node [block, 右边=1st] (2nd1) {2nd1};
  \node [block, 距 2nd1 0.7cm 以上] (2nd2) {2nd2};
  \node [block, 下方=2nd1] (2nd3) {2nd3};
  \node [block, 右边=2nd1] (3rd1) {3rd1};
  \node [block, 上方=3rd1] (3rd2) {3rd2};
  \node [block, 上方=3rd2] (3rd3) {3rd3};
  \node [block, 下方=3rd1] (3rd4) {3rd4};
  \node [block, 低于=3rd4] (3rd5) {3rd5};

  \path [行] (第一行) -- (第二行1);
  \path [行] (2nd1) -- (2nd2);
  \path [行] (2nd1) -- (2nd3);
  \path [行] (2nd2) -- (3rd3);
  \path [行] (第二行1) -- (第三行1);
  \path [行] (第一行) -- (第二行1);
\结束{tikzpicture}

\结束{文档}

像这样。我改变了垂直位置,2nd2但其他的保持不变。我是否必须为每个节点添加单独的垂直间距控制?

答案1

您可以通过输入以下代码来更改默认值:

\tikzset{node distance = 1cm and 2cm}

其中第一个参数是垂直节点距离,第二个参数是水平节点距离。如果只输入一个参数,则垂直和水平节点距离都将设置为该值。

作为特里克斯在评论中指出,在节点属性中,使用类似的above= of 2nd1而不是above of= 2nd1

答案2

我不太明白这个问题,所以我希望这是你想要的。如果你附上一份完整的文档(这样我们就可以复制粘贴并在系统上看到问题),事情就会简单得多。

在这里,您可以在一定范围内更改默认设置,但您的block样式node distance每次发布时都会重置。我将其设置为 2mm,以便我们更容易看到差异。

\documentclass[tikz]{standalone}
\usetikzlibrary{arrows,shapes.geometric,positioning}

\begin{document}
\begin{tikzpicture}[decision/.style={diamond, draw, text width=4.5em, text badly centered, node distance=3.5cm, inner sep=0pt},
                    block/.style   ={rectangle, draw, text width=6em, text centered, rounded corners, minimum height=4em, minimum height=2em},
                    cloud/.style   ={draw, ellipse, minimum height=2em},
                    line/.style    ={draw,-latex'},
                    node distance = 1cm, 
                    auto]
    \node [block] (1st) {1st};
    \node [block, right= of 1st]  (2nd1) {2nd1};
\begin{scope}[node distance=2mm and 10mm]%Here we change it for everything inside this scope
    \node [block, above= of 2nd1] (2nd2) {2nd2};
    \node [block, below= of 2nd1] (2nd3) {2nd3};
    \node [block, right= of 2nd1] (3rd1) {3rd1};
    \node [block, above= of 3rd1] (3rd2) {3rd2};
    \node [block, above= of 3rd2] (3rd3) {3rd3};
\end{scope}
    \node [block, below= of 3rd1] (3rd4) {3rd4};
    \node [block, below= of 3rd4] (3rd5) {3rd5};

    \path [line] (1st) -- (2nd1);
    \path [line] (2nd1) -- (2nd2);
    \path [line] (2nd1) -- (2nd3);
    \path [line] (2nd2) -- (3rd3);
    \path [line] (2nd1) -- (3rd1);
    \path [line] (1st) -- (2nd1);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容