5

Can I use \foreach inside of decoration = {markings, ...?

\documentclass[convert = false, tikz]{standalone}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{arrows}

\begin{document}
\begin{tikzpicture}
  \begin{scope}[decoration = {markings,
      \foreach \loc in {.1, .2, ..., 1}{
        mark = at position \loc with {\arrow{latex}},
      }
    }]
    \draw[postaction = decorate] (0, 0) -- (2,3);
  \end{scope}
\end{tikzpicture}
\end{document}

This code freezes on compilation.

0

1 Answer 1

8

This doesn't work (at least with your syntax). Though, the decorations.markings library provides a different syntax for the mark key that offers this.

Simply use

mark = between positions .1 and 1 step .1 with {\arrow{latex}}

You will face one problem here though, because due to TeX’s imprecision the last step with the value 1 will not be placed. But in this case it is better to place the last arrow as always using -latex so that the line gets shorten correctly.

Code

\documentclass[convert = false, tikz]{standalone}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{arrows}

\begin{document}
\begin{tikzpicture}
  \begin{scope}[decoration = {markings,
        mark=between positions .1 and 1 step .1 with {\arrow{latex}},
    }]
    \draw[postaction = decorate, -latex] (0, 0) -- (2,3);
  \end{scope}
\end{tikzpicture}
\end{document}

Output

enter image description here

You must log in to answer this question.

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