节点距离“和”命令不起作用

节点距离“和”命令不起作用

我正在尝试使用 TikZ 构建流程图。我希望​​水平和垂直间距不同。因此,我使用node distance=2.5cm and 1cm。但是,第二个距离(1cm)被忽略,并且 2.5 cm 用于水平和垂直节点距离。

此外,我尝试改变第二个值,但所有节点仍然保持 2.5 厘米的距离。

梅威瑟:

\documentclass[]{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,shapes,arrows,positioning}
\usetikzlibrary{calc} 
\usepackage[]{xcolor}
\usetikzlibrary{positioning}
\begin{document}

\definecolor{tmp}{RGB}{173, 198, 16}
\tikzstyle{block} = [rectangle, draw, fill=tmp!80, 
    text width=5em, text centered,  minimum height=4em]
\begin{figure}
\small
\begin{tikzpicture}[node distance=2.5cm and 1cm]
    \node [block] (A) {A};
    \node [block,right of=A] (B) {B};
    \node [block,right of=B] (C) {C};
    \node [block,right of=C] (D) {D};
    \node [block,right of=D] (E) {E};
    \node [block,below of=E] (F) {F};
    \node [block,left of=F] (G) {G};
    \node [block,left of=G] (H) {H};
    \node [block,below of=A] (I) {I};
    \node [block,below of=I] (J) {J};
    \node [block,right of=J] (K) {K};
    \node [block,below of=H] (L) {L};
    \node [block,below of=G] (M) {M};

\end{tikzpicture}
\end{figure}
\end{document}

我搜索了互联网,我相信我使用的方法是node distance=2.5cm and 1cm正确的。但为什么它不起作用呢?

答案1

right of= 和 right=of 的区别在于,前者使用节点中心作为参考点,而后者使用边界。使用后者可以正常工作。

\documentclass[]{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,shapes,arrows,positioning}
\usetikzlibrary{calc} 
\usepackage[]{xcolor}
\usetikzlibrary{positioning}
\begin{document}

\definecolor{tmp}{RGB}{173, 198, 16}
\tikzstyle{block} = [rectangle, draw, fill=tmp!80, 
    text width=5em, text centered,  minimum height=4em]
\begin{figure}
\small
\begin{tikzpicture}[node distance=3cm and 1cm,auto]
    \node [block] (A) {A};
    \node [block,right= of A] (B) {B};
    \node [block,right= of B] (C) {C};
    \node [block,right= of C] (D) {D};
    \node [block,right= of D] (E) {E};
    \node [block,below= of E] (F) {F};
    \node [block,left= of F] (G) {G};
    \node [block,left= of G] (H) {H};
    \node [block,below= of A] (I) {I};
    \node [block,below= of I] (J) {J};
    \node [block,right= of J] (K) {K};
    \node [block,below= of H] (L) {L};
    \node [block,below= of G] (M) {M};

\end{tikzpicture}
\end{figure}
\end{document}

编辑:有关更多信息,请参阅问题第二条评论中的链接。

相关内容