5

I'm using the decorations.markings tikz library to place circles evenly along a path:

\documentclass{article}

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

\begin{document}

\begin{tikzpicture}[
    decoration={
        markings,
        mark=between positions 0 and 1 step 0.2 with {\fill circle(2pt);}
    }
]
    \draw [postaction={decorate}, color=black] (0,1) to[out=30, in=100] (2,0.5);
\end{tikzpicture}

\end{document}

The code above produces

enter image description here

which doesn't include a node at the end point of the curve. Increasing the end point position (e.g, changing 1 to 1.2, 1.3, 100, etc.) doesn't change the output.

How do I include the circle at the end without manually placing a circle node at that coordinate?

  • 1
    It's the precision problem of 0, 0.2000001,...,. Try 0 and 1.01 in the decoration – percusse Oct 18 '17 at 13:45
  • That doesn't work for me. Further, the issue remains when I use a step that can be represented exactly in floating point, e.g., 0.25 or 0.125. – Chester Oct 18 '17 at 13:54
4

As percusse says, this seems to be a rounding problem. Using a step of 0.1999 produces the expected output:

enter image description here

Here is the full code:

\documentclass{article}

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

\begin{document}

\begin{tikzpicture}[
    decoration={
        markings,
        mark=between positions 0 and 1 step 0.1999 with {\fill circle(2pt);}
    }
]
    \draw [postaction={decorate}, color=black] (0,1) to[out=30, in=100] (2,0.5);
\end{tikzpicture}

\end{document}

Amusingly, using a step of 0.19999 again leads to the image in the OP.

  • I'm not entirely convinced of the rounding error argument, since there should be no rounding error for step 0.25 since this can be represented exactly in floating point, and yet step 0.25 leads to the same problem. Of course, I am ignorant of how the text step 0.25 is eventually converted to a float, and this process may very well introduce rounding errors. Anyhow, this answer clearly provides a working solution to get the desired result, which is all that matters for me in the end! – Chester Oct 25 '17 at 13:10
  • @Chester I think that the (rounding?) error comes from putting a point on the curve, so the step is going to be "deformed" from the "nice" number 0.25 into something that does not have a "nice" floating point expression. This is, however, just a guess because I don't know anything about what the tikz code actually does. – Andrew Oct 25 '17 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.