Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 7 down vote accepted

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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