添加装饰点注释

添加装饰点注释

我正在绘制如下图所示的图表:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{decorations.shapes}
\begin{document}
\tiny
\begin{tikzpicture}
\tikzset{dot/.style 2 args=
{decorate,decoration={shape backgrounds,shape=circle,shape size=#1,shape sep=#2}}}
    \coordinate (O) at (0,0);
       \draw (O)
        \foreach \n in {1,...,4} {
         -- ++(-120:{\n*3-2}) --  ++(0:{\n*3-1}) -- ++(120:{\n*3})
       };
       \draw[dot={2pt}{1cm},fill] (O)
        \foreach \n in {1,...,4} {
         -- ++(-120:{\n*3-2}) --  ++(0:{\n*3-1}) -- ++(120:{\n*3})
       };
\end{tikzpicture}
\end{document}

但我有两个问题:

  1. 如何注释 foreach 循环中的点?我希望除了每个点之外还能得到“1,2,3,...”。
  2. 我们可以将两个 \draw 命令合并为一个命令吗?

在此处输入图片描述

答案1

\documentclass[tikz]{standalone}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}[dot/.style={
  postaction=decorate,
  decoration={markings,mark= between positions 0 and 1 step #1mm with{%
    \node[circle,inner sep=0.5pt,fill, label=\pgfdecoratedangle-90:{%
      \number\numexpr\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}-1}]{};%
    }
  }
}
]

\coordinate (O) at (0,0);
   \draw[dot=10] (O)
      \foreach \n in {1,...,4} {
         -- ++(-120:{\n*3-2}) --  ++(0:{\n*3-1}) -- ++(120:{\n*3})
      };
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

一个修改后的版本,用垂直线来装饰。

\documentclass[tikz,border=10pt,convert={outfile=\jobname.jpg}]{standalone}
\usetikzlibrary{decorations.markings,calc}
\begin{document}
\tiny\begin{tikzpicture}
\tikzset{dot/.style={
  postaction=decorate,
   decoration={markings,mark=between positions 0 and 1 step #1mm with{%
    \pgfmathsetmacro{\desc}{int(\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}-1)}
    \draw (0,-3pt) -- node [label={\pgfdecoratedangle-90:\desc}] {} ++(0,6pt);
    } 
    }
  }
}
\def\m{5}
\coordinate (O) at (0,0);
   \draw[dot=3] (O)
      \foreach \n in {1,...,22} {
         -- ++({360/\m*Mod(\n,\m)}:{\n*0.3})
      };
\end{tikzpicture}
\end{document}

输出: 在此处输入图片描述

相关内容