我使用 tikz 图形制作了下图。在节点 (3) 和 (4) 中,我使用了相等相对命令。成功了!
我想切换到一个更好的选项,用于多次重复(例如 4 次)相对命令。在我的复杂问题中,我需要相对距离,因此“节点距离 = 4cm”没有帮助。
在节点(5)中我有一个成功更改below of = 1, right of = 1
(below right = of 1
带有库positioning
和可选参数on grid
)
\documentclass[border = 2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[every node/.style={draw,rectangle},on grid]
\draw[help lines] (-1,1) grid (3,-5);
\begin{scope}%[node distance= 1cm and 1cm]
\node (1) at (0,0) {1};
\node [below of = 1] (2) {2};
\node [below of = 1, below of = 1,below of = 1,below of = 1] (3) {3};
\node [right of = 1, right of = 1] (4) {4};
%\node [below of = 1, right of = 1] (5) {5};
\node [below right = of 1] (5) {5};
\end{scope}
\end{tikzpicture}
\end{document}
输出:
答案1
简单举个例子,现在没有时间说更多。
\documentclass[border = 2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[
every node/.style={draw,rectangle},
on grid
]
\newcommand\nd{1}
\draw[help lines] (-1,1) grid (3,-3);
\begin{scope}[node distance=\nd cm and \nd cm]
\node (1) at (0,0) {1};
\node [below = of 1] (2) {2};
\node [below = 4*\nd cm of 1] (3) {3};
\node [right = 2*\nd of 1] (4) {4};
\node [below right = of 1] (5) {5};
\end{scope}
\end{tikzpicture}
\end{document}