0

I would like to draw an edge between two nodes in tikz, but this edge should be both "dotted" and the dots must be a distinct shape (not dots or dashes). Currently, I am aiming at getting the shape of dots to be a start (*). However, a nice solution would be one that is generic enough that I can define any reasonable shape (say, a triangle, star, hexagon) and get the edge in dotted style.

EDIT: thanks for the comments, I managed to get some stuff working. However, I am still having a bit of issues. Now I have the MWE below:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{tikz} \usepackage{subcaption} \usetikzlibrary{arrows} \usetikzlibrary{snakes} \usetikzlibrary{shapes.geometric} \usetikzlibrary{shapes} \usetikzlibrary{decorations.shapes} \usetikzlibrary{positioning} \usetikzlibrary{patterns}

\begin{document}

\begin{tikzpicture}[->,=>stealth'] 
    \node[draw,circle,fill=black] (a) at (0,-0.5) {};
    \node[draw,circle,fill=black] (b) at (3.5,-3) {};
    \path[very thick]
        (a) edge[decorate,decoration={crosses, shape evenly spread=6, shape size={.15cm}}] node {} (b)
    ;

\end{tikzpicture}

\end{document}

The problem is that the shape evenly spread or shape sep options do not seem to work for me.

Does anyone else have the same problem? It doesn't matter how much I change the parameters for either one of them, the figure it generates is always the same.

a_guy
  • 3
  • 1
    See https://tikz.dev/tikz-decorations, there are some "dotted style" examples there with triangles and crosses. – Marijn Feb 06 '23 at 11:52
  • 1
    Or on the site here https://tex.stackexchange.com/questions/150467/is-this-possible-in-tikz/150490 for example, which you could adapt to show only the stars and not the line. See also https://tex.stackexchange.com/a/76551/. – Marijn Feb 06 '23 at 11:58
  • Thanks @Marijn. Your comment helped a lot, but now I am stuck at another point. Do you know what I can do, or if I am doing something wrong? – a_guy Feb 06 '23 at 15:41

1 Answers1

2

shape evenly spread and shape sep are not valid options for the crosses decoration. But you can use segment length to change the distance between the (centers of the) crosses.

enter image description here

\documentclass{article}

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

\begin{document} \begin{tikzpicture} \path[very thick] (0,-.5) edge[decorate, decoration={crosses, segment length=7mm, shape size=.15cm}] node {} (3.5,-3); \path[very thick, red] (1,-.5) edge[decorate, decoration={crosses, segment length=5mm, shape size=.15cm}] node {} (4.5,-3); \path[very thick, blue] (2,-.5) edge[decorate, decoration={crosses, segment length=2mm, shape size=.15cm}] node {} (5.5,-3); \end{tikzpicture} \end{document}

Note that you can define your own style to make the code a bit simpler:

\documentclass{article}

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

\tikzset{mycrosses/.style={very thick, decorate, decoration={crosses, segment length=#1, shape size=.15cm}}, mycrosses/.default={7mm}}

\begin{document} \begin{tikzpicture} \draw[mycrosses] (0,-.5) -- (3.5,-3); \draw[mycrosses=5mm, red] (1,-.5) -- (4.5,-3); \draw[mycrosses=2mm, blue] (2,-.5) -- (5.5,-3); \end{tikzpicture} \end{document}

Sandy G
  • 42,558
  • Oh, right! Somehow I was thinking that they applied to crosses as well. My mistake. Thanks, I managed to make it work now! – a_guy Feb 07 '23 at 11:50