在foreach中定义不同的位置

在foreach中定义不同的位置

在下面的代码中

\begin{tikzpicture}
  \foreach \pos in {0,...,5} {
    \pic at (1.85*\pos,0) {cross};
    \node[formula] at ($(1.85*\pos,0)+(0.4,0.4)$) {Na};
  }
\end{tikzpicture}

可以分配不同的位置吗?例如,位置 1 1.85,位置 2 2.85,位置 3 1.85

答案1

您的意思是将节点位置移动 1cm?如果是这种情况,请尝试:

1.

\begin{tikzpicture}
  \foreach \pos in {0,...,5} {
    \pic at (1.85*\pos,0) {cross};
    \node[formula, xshift=1cm] at ($(1.85*\pos,0)+(0.4,0.4)$) {Na};
  }
\end{tikzpicture}

2.

\begin{tikzpicture}
  \foreach \pos in {0,...,5} {
    \pic at (1.85*\pos,0) {cross};
    \node[formula] at ($({1+1.85*\pos},0)+(0.4,0.4)$) {Na};
  }
\end{tikzpicture}

附录:

3.

\begin{tikzpicture}
  \foreach \pos in {0,...,5} {
    \pic at (1.85*\pos,0) {cross};
    \node[formula] at ($(1.85*\pos,0)+(1.4,0.4)$) {Na};
  }
\end{tikzpicture}

4.

\begin{tikzpicture}
  \foreach \pos in {0,...,5} {
    \pic at (1.85*\pos,0) {cross};
    \node[formula] at ({1.4+1.85*\pos},0.4) {Na};
  }
\end{tikzpicture}

5.

\begin{tikzpicture}
  \foreach \pos in {0,...,5} {
    \pic (cross\pos) at (1.85*\pos,0) {cross};
    \node[formula,above right=1cm and 0.4cm of cross\pos] {Na};
  }
\end{tikzpicture}
  1. ETC

相关内容