Post by DoxDear all,
I'm trying to use Tikz for drawing Feynman diagrams, and I'd need a `special feature' for arrows. I'd like that if a path is specified by,
\draw[fermion] (-1,0) -- (0,0) arc (-180:0:5mm) -- (2,0);
each of the segments, which describe the path, would have an arrow tip in the middle.
Is this possible? Thank you!
DOX
Hi,
One way of doing this is to decorate a decoration as follows:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
\tikzset{
arrow middle/.style={
postaction=decorate,
decoration={
markings,
mark=at position 0.5 with{\arrow{>}},
}
},
arrow middle segments/.style={
postaction=decorate,
decoration={
show path construction,
moveto code={},
lineto code={
\path [arrow middle] (\tikzinputsegmentfirst) --
(\tikzinputsegmentlast);
},
curveto code={
\path [arrow middle] (\tikzinputsegmentfirst) .. controls
(\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb)
.. (\tikzinputsegmentlast);
},
closepath code={\path [arrow middle] (\tikzinputsegmentfirst) --
(\tikzinputsegmentlast);}
}
}
}
\tikz\draw [arrow middle segments] (-1,0) -- (0,0) arc (-180:0:5mm) --
(2,0);
\tikz\draw [arrow middle segments] (0,0) -| (3,2) .. controls (3,3)
and (0,3) .. (0,2) -- (0,0);
\tikz\draw [arrow middle segments] (0,0) circle [radius=1cm];
\tikz\draw [arrow middle segments] (0,0) rectangle (2, 2);
\tikz\foreach \x in {0,...,5}
\foreach \y in {0,...,5}
\draw [arrow middle segments, shift={(\x, \y)}] (0,0) |- (1,1);
\end{document}
Note, however, that this will put arrows on every *segment* and an 180
degree arc is approximated with two bezier curves.
Mark