TikZ arrowheads on every dash of dashed line











up vote
5
down vote

favorite
1












I'd like to create a dashed line in TikZ with an arrow head at the end of each dash. The following code accomplishes this using a foreach loop but looking for a way to do this with a style key instead. Something similar to



draw [densely dashed, ->] (0,0) -- ++(100pt,0);


but places arrowheads on all dashes not just the end.



MWE:



documentclass[12pt]{article}
usepackage{tikz}
begin{document}
begin{tikzpicture}
draw [densely dashed] (0,0) -- ++(100pt,0);
foreach i in {0,5,10,...,100}{%
draw [->] (i*1pt,-0.25) -- ++(3pt,0);
}
end{tikzpicture}
end{document}









share|improve this question


























    up vote
    5
    down vote

    favorite
    1












    I'd like to create a dashed line in TikZ with an arrow head at the end of each dash. The following code accomplishes this using a foreach loop but looking for a way to do this with a style key instead. Something similar to



    draw [densely dashed, ->] (0,0) -- ++(100pt,0);


    but places arrowheads on all dashes not just the end.



    MWE:



    documentclass[12pt]{article}
    usepackage{tikz}
    begin{document}
    begin{tikzpicture}
    draw [densely dashed] (0,0) -- ++(100pt,0);
    foreach i in {0,5,10,...,100}{%
    draw [->] (i*1pt,-0.25) -- ++(3pt,0);
    }
    end{tikzpicture}
    end{document}









    share|improve this question
























      up vote
      5
      down vote

      favorite
      1









      up vote
      5
      down vote

      favorite
      1






      1





      I'd like to create a dashed line in TikZ with an arrow head at the end of each dash. The following code accomplishes this using a foreach loop but looking for a way to do this with a style key instead. Something similar to



      draw [densely dashed, ->] (0,0) -- ++(100pt,0);


      but places arrowheads on all dashes not just the end.



      MWE:



      documentclass[12pt]{article}
      usepackage{tikz}
      begin{document}
      begin{tikzpicture}
      draw [densely dashed] (0,0) -- ++(100pt,0);
      foreach i in {0,5,10,...,100}{%
      draw [->] (i*1pt,-0.25) -- ++(3pt,0);
      }
      end{tikzpicture}
      end{document}









      share|improve this question













      I'd like to create a dashed line in TikZ with an arrow head at the end of each dash. The following code accomplishes this using a foreach loop but looking for a way to do this with a style key instead. Something similar to



      draw [densely dashed, ->] (0,0) -- ++(100pt,0);


      but places arrowheads on all dashes not just the end.



      MWE:



      documentclass[12pt]{article}
      usepackage{tikz}
      begin{document}
      begin{tikzpicture}
      draw [densely dashed] (0,0) -- ++(100pt,0);
      foreach i in {0,5,10,...,100}{%
      draw [->] (i*1pt,-0.25) -- ++(3pt,0);
      }
      end{tikzpicture}
      end{document}






      tikz-pgf tikz-arrows






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 6 hours ago









      user2501235

      645




      645






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          4
          down vote













          I guess for this one of the simplest possibilities will be to employ decorations.markings.



          documentclass[12pt]{article}
          usepackage{tikz}
          usetikzlibrary{decorations.markings}
          begin{document}
          begin{tikzpicture}
          draw [dash pattern=on 3pt off 2pt,postaction={decorate,
          decoration={markings,
          mark=between positions 3pt and 1 step 5pt with {arrow{>};}}}] (0,0) -- ++(100pt,0);
          end{tikzpicture}
          end{document}


          enter image description here



          Depending on the real application, one could make this a style, or, what might be better for curved paths, just declare a new (meta) decoration. Luckily, the pgfmanual has on p. 1007 a meta decoration that one only has to slightly modify to arrive at



          documentclass[tikz,border=3.14mm]{standalone}
          usetikzlibrary{decorations,arrows.meta}
          pgfdeclaremetadecoration{many arrows}{initial}{
          state{initial}[width=0pt, next state=arrow] {
          pgfmathdivide{100}{pgfmetadecoratedpathlength}
          letfactorpgfmathresult
          %pgfsetlinewidth{1pt}
          pgfset{/pgf/decoration/segment length=4pt}
          }
          state{arrow}[
          switch if less than=pgfmetadecorationsegmentlength to final, width=pgfmetadecorationsegmentlength/3,
          next state=end arrow]
          {
          decoration{curveto}
          beforedecoration
          {
          pgfpathmoveto{pgfpointmetadecoratedpathfirst}
          } }
          state{end arrow}[width=pgfmetadecorationsegmentlength/3, next state=move] {
          decoration{curveto}
          beforedecoration{pgfpathmoveto{pgfpointmetadecoratedpathfirst}}
          afterdecoration
          {
          pgfsetarrowsend{Latex[length=1pt,width=1pt]}
          pgfusepath{stroke}
          }
          }
          state{move}[width=pgfmetadecorationsegmentlength/2, next state=arrow]{} state{final}{}
          }
          begin{document}
          begin{tikzpicture}
          draw[ultra thin,decorate,decoration={many arrows,meta-segment length=3pt}] (0,0) .. controls (0,2) and (3,2) .. (3,0)
          .. controls (3,-2) and (0,-2) .. (0,-4)
          .. controls (0,-6) and (3,-6) .. (3,-8)
          .. controls (3,-10) and (0,-10) .. (0,-8);
          end{tikzpicture}
          end{document}


          Here I zoom into the outcome to show that the arrows are tiny. (Recall that the diameter is 3cm.)



          enter image description here






          share|improve this answer























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "85"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f463011%2ftikz-arrowheads-on-every-dash-of-dashed-line%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            4
            down vote













            I guess for this one of the simplest possibilities will be to employ decorations.markings.



            documentclass[12pt]{article}
            usepackage{tikz}
            usetikzlibrary{decorations.markings}
            begin{document}
            begin{tikzpicture}
            draw [dash pattern=on 3pt off 2pt,postaction={decorate,
            decoration={markings,
            mark=between positions 3pt and 1 step 5pt with {arrow{>};}}}] (0,0) -- ++(100pt,0);
            end{tikzpicture}
            end{document}


            enter image description here



            Depending on the real application, one could make this a style, or, what might be better for curved paths, just declare a new (meta) decoration. Luckily, the pgfmanual has on p. 1007 a meta decoration that one only has to slightly modify to arrive at



            documentclass[tikz,border=3.14mm]{standalone}
            usetikzlibrary{decorations,arrows.meta}
            pgfdeclaremetadecoration{many arrows}{initial}{
            state{initial}[width=0pt, next state=arrow] {
            pgfmathdivide{100}{pgfmetadecoratedpathlength}
            letfactorpgfmathresult
            %pgfsetlinewidth{1pt}
            pgfset{/pgf/decoration/segment length=4pt}
            }
            state{arrow}[
            switch if less than=pgfmetadecorationsegmentlength to final, width=pgfmetadecorationsegmentlength/3,
            next state=end arrow]
            {
            decoration{curveto}
            beforedecoration
            {
            pgfpathmoveto{pgfpointmetadecoratedpathfirst}
            } }
            state{end arrow}[width=pgfmetadecorationsegmentlength/3, next state=move] {
            decoration{curveto}
            beforedecoration{pgfpathmoveto{pgfpointmetadecoratedpathfirst}}
            afterdecoration
            {
            pgfsetarrowsend{Latex[length=1pt,width=1pt]}
            pgfusepath{stroke}
            }
            }
            state{move}[width=pgfmetadecorationsegmentlength/2, next state=arrow]{} state{final}{}
            }
            begin{document}
            begin{tikzpicture}
            draw[ultra thin,decorate,decoration={many arrows,meta-segment length=3pt}] (0,0) .. controls (0,2) and (3,2) .. (3,0)
            .. controls (3,-2) and (0,-2) .. (0,-4)
            .. controls (0,-6) and (3,-6) .. (3,-8)
            .. controls (3,-10) and (0,-10) .. (0,-8);
            end{tikzpicture}
            end{document}


            Here I zoom into the outcome to show that the arrows are tiny. (Recall that the diameter is 3cm.)



            enter image description here






            share|improve this answer



























              up vote
              4
              down vote













              I guess for this one of the simplest possibilities will be to employ decorations.markings.



              documentclass[12pt]{article}
              usepackage{tikz}
              usetikzlibrary{decorations.markings}
              begin{document}
              begin{tikzpicture}
              draw [dash pattern=on 3pt off 2pt,postaction={decorate,
              decoration={markings,
              mark=between positions 3pt and 1 step 5pt with {arrow{>};}}}] (0,0) -- ++(100pt,0);
              end{tikzpicture}
              end{document}


              enter image description here



              Depending on the real application, one could make this a style, or, what might be better for curved paths, just declare a new (meta) decoration. Luckily, the pgfmanual has on p. 1007 a meta decoration that one only has to slightly modify to arrive at



              documentclass[tikz,border=3.14mm]{standalone}
              usetikzlibrary{decorations,arrows.meta}
              pgfdeclaremetadecoration{many arrows}{initial}{
              state{initial}[width=0pt, next state=arrow] {
              pgfmathdivide{100}{pgfmetadecoratedpathlength}
              letfactorpgfmathresult
              %pgfsetlinewidth{1pt}
              pgfset{/pgf/decoration/segment length=4pt}
              }
              state{arrow}[
              switch if less than=pgfmetadecorationsegmentlength to final, width=pgfmetadecorationsegmentlength/3,
              next state=end arrow]
              {
              decoration{curveto}
              beforedecoration
              {
              pgfpathmoveto{pgfpointmetadecoratedpathfirst}
              } }
              state{end arrow}[width=pgfmetadecorationsegmentlength/3, next state=move] {
              decoration{curveto}
              beforedecoration{pgfpathmoveto{pgfpointmetadecoratedpathfirst}}
              afterdecoration
              {
              pgfsetarrowsend{Latex[length=1pt,width=1pt]}
              pgfusepath{stroke}
              }
              }
              state{move}[width=pgfmetadecorationsegmentlength/2, next state=arrow]{} state{final}{}
              }
              begin{document}
              begin{tikzpicture}
              draw[ultra thin,decorate,decoration={many arrows,meta-segment length=3pt}] (0,0) .. controls (0,2) and (3,2) .. (3,0)
              .. controls (3,-2) and (0,-2) .. (0,-4)
              .. controls (0,-6) and (3,-6) .. (3,-8)
              .. controls (3,-10) and (0,-10) .. (0,-8);
              end{tikzpicture}
              end{document}


              Here I zoom into the outcome to show that the arrows are tiny. (Recall that the diameter is 3cm.)



              enter image description here






              share|improve this answer

























                up vote
                4
                down vote










                up vote
                4
                down vote









                I guess for this one of the simplest possibilities will be to employ decorations.markings.



                documentclass[12pt]{article}
                usepackage{tikz}
                usetikzlibrary{decorations.markings}
                begin{document}
                begin{tikzpicture}
                draw [dash pattern=on 3pt off 2pt,postaction={decorate,
                decoration={markings,
                mark=between positions 3pt and 1 step 5pt with {arrow{>};}}}] (0,0) -- ++(100pt,0);
                end{tikzpicture}
                end{document}


                enter image description here



                Depending on the real application, one could make this a style, or, what might be better for curved paths, just declare a new (meta) decoration. Luckily, the pgfmanual has on p. 1007 a meta decoration that one only has to slightly modify to arrive at



                documentclass[tikz,border=3.14mm]{standalone}
                usetikzlibrary{decorations,arrows.meta}
                pgfdeclaremetadecoration{many arrows}{initial}{
                state{initial}[width=0pt, next state=arrow] {
                pgfmathdivide{100}{pgfmetadecoratedpathlength}
                letfactorpgfmathresult
                %pgfsetlinewidth{1pt}
                pgfset{/pgf/decoration/segment length=4pt}
                }
                state{arrow}[
                switch if less than=pgfmetadecorationsegmentlength to final, width=pgfmetadecorationsegmentlength/3,
                next state=end arrow]
                {
                decoration{curveto}
                beforedecoration
                {
                pgfpathmoveto{pgfpointmetadecoratedpathfirst}
                } }
                state{end arrow}[width=pgfmetadecorationsegmentlength/3, next state=move] {
                decoration{curveto}
                beforedecoration{pgfpathmoveto{pgfpointmetadecoratedpathfirst}}
                afterdecoration
                {
                pgfsetarrowsend{Latex[length=1pt,width=1pt]}
                pgfusepath{stroke}
                }
                }
                state{move}[width=pgfmetadecorationsegmentlength/2, next state=arrow]{} state{final}{}
                }
                begin{document}
                begin{tikzpicture}
                draw[ultra thin,decorate,decoration={many arrows,meta-segment length=3pt}] (0,0) .. controls (0,2) and (3,2) .. (3,0)
                .. controls (3,-2) and (0,-2) .. (0,-4)
                .. controls (0,-6) and (3,-6) .. (3,-8)
                .. controls (3,-10) and (0,-10) .. (0,-8);
                end{tikzpicture}
                end{document}


                Here I zoom into the outcome to show that the arrows are tiny. (Recall that the diameter is 3cm.)



                enter image description here






                share|improve this answer














                I guess for this one of the simplest possibilities will be to employ decorations.markings.



                documentclass[12pt]{article}
                usepackage{tikz}
                usetikzlibrary{decorations.markings}
                begin{document}
                begin{tikzpicture}
                draw [dash pattern=on 3pt off 2pt,postaction={decorate,
                decoration={markings,
                mark=between positions 3pt and 1 step 5pt with {arrow{>};}}}] (0,0) -- ++(100pt,0);
                end{tikzpicture}
                end{document}


                enter image description here



                Depending on the real application, one could make this a style, or, what might be better for curved paths, just declare a new (meta) decoration. Luckily, the pgfmanual has on p. 1007 a meta decoration that one only has to slightly modify to arrive at



                documentclass[tikz,border=3.14mm]{standalone}
                usetikzlibrary{decorations,arrows.meta}
                pgfdeclaremetadecoration{many arrows}{initial}{
                state{initial}[width=0pt, next state=arrow] {
                pgfmathdivide{100}{pgfmetadecoratedpathlength}
                letfactorpgfmathresult
                %pgfsetlinewidth{1pt}
                pgfset{/pgf/decoration/segment length=4pt}
                }
                state{arrow}[
                switch if less than=pgfmetadecorationsegmentlength to final, width=pgfmetadecorationsegmentlength/3,
                next state=end arrow]
                {
                decoration{curveto}
                beforedecoration
                {
                pgfpathmoveto{pgfpointmetadecoratedpathfirst}
                } }
                state{end arrow}[width=pgfmetadecorationsegmentlength/3, next state=move] {
                decoration{curveto}
                beforedecoration{pgfpathmoveto{pgfpointmetadecoratedpathfirst}}
                afterdecoration
                {
                pgfsetarrowsend{Latex[length=1pt,width=1pt]}
                pgfusepath{stroke}
                }
                }
                state{move}[width=pgfmetadecorationsegmentlength/2, next state=arrow]{} state{final}{}
                }
                begin{document}
                begin{tikzpicture}
                draw[ultra thin,decorate,decoration={many arrows,meta-segment length=3pt}] (0,0) .. controls (0,2) and (3,2) .. (3,0)
                .. controls (3,-2) and (0,-2) .. (0,-4)
                .. controls (0,-6) and (3,-6) .. (3,-8)
                .. controls (3,-10) and (0,-10) .. (0,-8);
                end{tikzpicture}
                end{document}


                Here I zoom into the outcome to show that the arrows are tiny. (Recall that the diameter is 3cm.)



                enter image description here







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 2 hours ago

























                answered 5 hours ago









                marmot

                80.3k491172




                80.3k491172






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f463011%2ftikz-arrowheads-on-every-dash-of-dashed-line%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

                    Mangá

                    Eduardo VII do Reino Unido