[Tex/LaTex] TikZ: Line with large dots

tikz-pgf

Is there a simple way to draw a line like with \draw[dotted] (0,0) -- (1,0); but with larger (radius about 1mm) and more distant (about 4mm) dots?

I've looked in the TikZ & PGF manual, section "15.3.2 Graphic Parameters: Dash Pattern" but found nothing useful.

My workaround is using a \foreach and drawing circle nodes.

Best Answer

You can use a decoration:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}

\begin{document}

\begin{tikzpicture}[decoration={markings,
  mark=between positions 0 and 1 step 6pt
  with { \draw [fill] (0,0) circle [radius=2pt];}}]
\path[postaction={decorate}] (0,0) to (4,0);
\end{tikzpicture}

\end{document}

enter image description here

Or using decorations.shapes:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.shapes}

\begin{document}

\tikzset{decorate sep/.style 2 args=
{decorate,decoration={shape backgrounds,shape=circle,shape size=#1,shape sep=#2}}}

\begin{tikzpicture}
\draw[decorate sep={2mm}{4mm},fill] (0,0) -- (4,0);
\draw[decorate sep={2mm}{6mm},fill] (0,1) -- (4,1);
\draw[decorate sep={1mm}{4mm},fill] (0,2) -- (4,2);
\end{tikzpicture}

\end{document}

enter image description here