TikZ arrowheads on every dash of dashed line
up vote
5
down vote
favorite
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
add a comment |
up vote
5
down vote
favorite
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
add a comment |
up vote
5
down vote
favorite
up vote
5
down vote
favorite
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
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
tikz-pgf tikz-arrows
asked Dec 3 at 17:53
user2501235
665
665
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
7
down vote
accepted
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}
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.)
Perfect, thanks!
– user2501235
Dec 4 at 14:35
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
7
down vote
accepted
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}
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.)
Perfect, thanks!
– user2501235
Dec 4 at 14:35
add a comment |
up vote
7
down vote
accepted
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}
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.)
Perfect, thanks!
– user2501235
Dec 4 at 14:35
add a comment |
up vote
7
down vote
accepted
up vote
7
down vote
accepted
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}
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.)
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}
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.)
edited Dec 3 at 22:43
answered Dec 3 at 19:25
marmot
82.1k492175
82.1k492175
Perfect, thanks!
– user2501235
Dec 4 at 14:35
add a comment |
Perfect, thanks!
– user2501235
Dec 4 at 14:35
Perfect, thanks!
– user2501235
Dec 4 at 14:35
Perfect, thanks!
– user2501235
Dec 4 at 14:35
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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