You could define a custom dash pattern with an on
length of 0pt
. If you set line cap=round
, you'll end up with perfect circles. The dash pattern
approach is much faster than using decorations
for the same purpose.
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw [line width=3pt, line cap=round, dash pattern=on 0pt off 2\pgflinewidth] (0,0) -- (3,0) to [out=0, in=0, looseness=2] (3,-1);
\end{tikzpicture}
\end{document}
The whole thing can of course be made into a new style so you just have to use dots
, and which allows you to comfortably set the dot diameter using dot diameter
and the dot spacing using dot spacing
\draw [dots] ...
\draw [red, dot diameter=5pt, dot spacing=5pt, dots] ...
\documentclass{article}
\usepackage{tikz}
\begin{document}
\makeatletter
\tikzset{
dot diameter/.store in=\dot@diameter,
dot diameter=3pt,
dot spacing/.store in=\dot@spacing,
dot spacing=10pt,
dots/.style={
line width=\dot@diameter,
line cap=round,
dash pattern=on 0pt off \dot@spacing
}
}
\makeatother
\begin{tikzpicture}
\draw [dots] (0,0) -- (3,0) to [out=0, in=0, looseness=2] (3,-1);
\end{tikzpicture}
\begin{tikzpicture}
\draw [red, dot diameter=5pt, dot spacing=5pt, dots] (0,0) -- (3,0) to [out=0, in=0, looseness=2] (3,-1);
\end{tikzpicture}
\end{document}
This answer proposes to use preaction
and|or postaction
to define a style which draws all three layers in one command but doesn't solve the problem about equally distributed 11 dots between two points.
\documentclass{article}
\usepackage{tikz}
\makeatletter
\tikzset{
dot diameter/.store in=\dot@diameter,
dot diameter=3pt,
dot spacing/.store in=\dot@spacing,
dot spacing=10pt,
dots/.style={
line width=\dot@diameter,
line cap=round,
dash pattern=on 0pt off \dot@spacing
},
mydots/.style={
dot spacing=3.8mm,
preaction={draw=black,
dot diameter=3mm,
dots},
draw = white,
dot diameter=2.5mm,
dots,
postaction={draw=black,
dot diameter=1mm,
dots},
}
}
\makeatother
\begin{document}
\begin{tikzpicture}
\draw [mydots] (0,0) -- (4,0);
\draw [mydots] (0,1) .. controls (3,1) and (4,2).. (3,3);
\end{tikzpicture}
\end{document}
Update: Parametric version: \mydots={dot dimension}{distance}
\documentclass[tikz,border=2mm]{standalone}
\makeatletter
\tikzset{
dot diameter/.store in=\dot@diameter,
dot diameter=3pt,
dot spacing/.store in=\dot@spacing,
dot spacing=10pt,
dots/.style={
line width=#1,
line cap=round,
dash pattern=on 0pt off \dot@spacing
},
mydots/.style 2 args={
dot spacing=#2,
preaction={draw=black,
dots=#1},
draw = white,
dots=.8*#1,
postaction={draw=black,
dots=.333*#1},
}
}
\makeatother
\begin{document}
\begin{tikzpicture}
\draw [mydots={3mm}{3.8mm}] (0,0) -- (4,0);
\draw [mydots={2mm}{5mm}] (0,1) .. controls (3,1) and (4,2).. (3,3);
\end{tikzpicture}
\end{document}
Best Answer