25

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.

2 Answers 2

32

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

1
  • Thanks for your help! I like your second solution more, it looks cleaner…
    – siegi
    Commented Apr 22, 2012 at 9:10
24

It's possible with simple options. Logically with dotted, you get only squares or rectangles.

For example :

\documentclass[11pt]{scrartcl}
\usepackage{tikz}    
\begin{document}
\begin{tikzpicture}
\tikzstyle{dotted}= [dash pattern=on \pgflinewidth off 4mm]  
\draw[dotted,line width = 2mm] (0,0) -- (5,0);
\end{tikzpicture}    
\end{document}

enter image description here

A strange idea is to use line cap=round to get circles instead squares. A pattern is a rectangle but with line cap=round you get a ice rink and if you reduce the width enough, you get circles. The method is funny.

update I added a style

\documentclass[11pt]{scrartcl}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[circle dotted/.style={dash pattern=on .05mm off 8mm,
                                         line cap=round}]
  \draw[line width = 2mm,circle dotted] (0,0) -- (10,0);
\end{tikzpicture}
\end{document}

enter image description here

1
  • This is indeed a funny solution, thanks :-)
    – siegi
    Commented Apr 22, 2012 at 9:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .