![如何在tikz图片中添加节点之间的距离](https://linux22.com/image/384116/%E5%A6%82%E4%BD%95%E5%9C%A8tikz%E5%9B%BE%E7%89%87%E4%B8%AD%E6%B7%BB%E5%8A%A0%E8%8A%82%E7%82%B9%E4%B9%8B%E9%97%B4%E7%9A%84%E8%B7%9D%E7%A6%BB.png)
我是 tikz 的新用户,在做我真正想做的事情时遇到了很多问题...我必须绘制一个由值参数化的图形。例如,这意味着第二个节点级别的节点数介于 0 和某个值之间。X
因此,我无法绘制完整的图形,但我必须使用\ldots
例如省略某些部分。
为此,我正在使用arrows
tikzautomata
库,但是在第二个节点级别遇到一个问题:我想要绘制的 4 个节点被覆盖了......这里是源代码:
\documentclass{standalone}
\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,automata,shapes}
\usepackage[latin1]{inputenc}
\begin{document}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=5cm,sibling distance=50cm,
semithick]
\tikzstyle{every state}=[
rounded rectangle,
fill=red,
draw=none,
text=white,
align=center,
inner sep=1pt,
text width=9.5em,
]
\tikzstyle{kernel} = [
inner sep=1pt,
node font=\itshape \small,
]
\node[state] (A) {$A(0:DIM\_X, 0)$};
\node[state] (B) [below left of=A] {$A(1, 1)$};
\node[state] (C) [below right of= A] {$A(DIM\_X-2, 1)$};
\node[state] (D) [below of=B] {$A(1, 2)$};
\node[state] (E) [right of=D] {$A(2, 2)$};
\node[state] (F) [below of=C] {$A(DIM\_X-2, 2)$};
\node[state] (G) [left of=F] {$A(DIM\_X-3, 2)$};
\path (A) edge node[kernel,swap] {S(1, 1)} (B)
edge node[kernel] {S(DIM\_X-2, 1)} (C)
;
\path (B) edge[-,dotted] (C);
\end{tikzpicture}
\end{document}
谢谢你的帮助:)
答案1
使用positioning
图书馆。
\documentclass{standalone}
\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,automata,shapes,positioning}
\usepackage[latin1]{inputenc}
\begin{document}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=5cm,sibling distance=50cm,
semithick]
\tikzstyle{every state}=[
rounded rectangle,
fill=red,
draw=none,
text=white,
align=center,
inner sep=1pt,
text width=9.5em,
]
\tikzstyle{kernel} = [
inner sep=1pt,
node font=\itshape \small,
]
\node[state] (A) {$A(0:DIM\_X, 0)$};
\node[state] (B) [below left=of A] {$A(1, 1)$};
\node[state] (C) [below right=of A] {$A(DIM\_X-2, 1)$};
\node[state] (D) [below=of B] {$A(1, 2)$};
\node[state] (E) [right=of D] {$A(2, 2)$};
\node[state] (F) [below=of C] {$A(DIM\_X-2, 2)$};
\node[state] (G) [left=of F] {$A(DIM\_X-3, 2)$};
\path (A) edge node[kernel,swap] {S(1, 1)} (B)
edge node[kernel] {S(DIM\_X-2, 1)} (C)
;
\path (B) edge[-,dotted] (C);
\end{tikzpicture}
\end{document}