I'm trying to create dotted lines with tikz where every dot has a defined size and a circle around it, with also a defined size.
First I applied this answer to create a dash pattern:
\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 }}
Then I plot these dotted lines in black - white - black on top of each other to achieve the desired effect. How can I change the tikzset to get this in one step?
The next problem is that it requires a defined dot-spacing which is fine if I'd knew the distance between the endpoints of my line, which I usually don't, so I'm fiddling around with the spacing manually. But I'd like to have a circled dot at the beginning and end node and the rest of the dots equally spaced inbetween. How can I achieve that equal distribution? Is it possible to define, say, exactly 11 dots on that line, equally distributed?
Thank you!
MWE
\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 }}\makeatother\begin{document} \begin{tikzpicture} \coordinate (A1) at (1,1); \coordinate (B1) at (5,1); \coordinate (A2) at (1,1.5); \coordinate (B2) at (5,1.5); % for reference frame \draw [black, thick] (A1.center) -- (B1.center) -- (B2.center) -- (A2.center) -- (A1.center); % three dot layers #1 \draw [black, dot diameter=3mm, dot spacing=3.8mm, dots] (A1.center) -- (B1.center); \draw [white, dot diameter=2.5mm, dot spacing=3.8mm, dots] (A1.center) -- (B1.center); \draw [black, dot diameter=1mm, dot spacing=3.8mm, dots] (A1.center) -- (B1.center); % three dot layers #2 \draw [black, dot diameter=3mm, dot spacing=4mm, dots] (A2.center) -- (B2.center); \draw [white, dot diameter=2.5mm, dot spacing=4mm, dots] (A2.center) -- (B2.center); \draw [black, dot diameter=1mm, dot spacing=4mm, dots] (A2.center) -- (B2.center); \end{tikzpicture}\end{document}
The solid line is just for orientation, there shouldn't be a connect between the dots. The upper dotted line is manually adjusted to get the correct spacing.