TikZ 绘图教程在线参考手册

样式与布局

用命名样式和局部偏移组织两组可重复的几何元素。

两行圆形元件,第二行整体右移
两行圆形元件,第二行整体右移

运行与理解

  1. unit/.style 把描边、填充和最小尺寸定义集中在一起。每个节点通过 [unit] 使用同一套样式。
  2. scope 的 shift 对作用域内的坐标整体平移。两行各自从横坐标 0 开始,第二组位置由外层偏移决定。

源码

\documentclass[tikz,border=7pt]{standalone}
\begin{document}
\begin{tikzpicture}[unit/.style={circle,draw=teal!70!black,fill=teal!12,minimum size=7mm}]
  \foreach \x in {0,1,2,3}
    \node[unit] at (\x,0) {};
  \begin{scope}[shift={(.5,-.8)}]
    \foreach \x in {0,1,2}
      \node[unit] at (\x,0) {};
  \end{scope}
\end{tikzpicture}
\end{document}
下载 .tex

练习

把 shift 的横向偏移从 0.5 调到 0。此时两行应该上下对齐。再修改 unit 的填色,确认所有节点同步变化。

阅读对应的上游手册章节