Discussion:
Arrows and Tikz
(too old to reply)
Dox
2012-04-20 13:17:07 UTC
Permalink
Dear 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
John Wingate
2012-04-20 20:36:13 UTC
Permalink
Post by Dox
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!
When I wanted to do something similar--put arrows in the middle of graph
edges--I found the section in the manual on Mark Decorations, for
putting arrows (and other stuff) at arbitrary points on a path.

Here is an example:

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}
\draw [postaction=decorate,
decoration={markings,
mark=at position 0.5cm with{\arrow{>}},
mark=at position 0.51 with{\arrow{>}},
mark=at position 0.87 with{\arrow{stealth}}}]
(-1,0) -- (0,0) arc (-180:0:5mm) -- (2,0);
\end{tikzpicture}
\end{document}

Does this do anything like what you are after?

There is probably a way to avoid having to explicitly treat each
arrowhead separately, but I am a tikz novice, and someone with more
knowledge will have to step in for any further advice.
--
John Wingate Mathematics is the art which teaches
***@tds.net one how not to make calculations.
--Oscar Chisini
Dox
2012-04-21 12:30:00 UTC
Permalink
Thank you Oscar, this is what I expected, however, Is there a way of doing so, without declaring the positions one by one?

Cheers

PD: Beautiful example!
corporal
2012-04-22 08:26:41 UTC
Permalink
Dox, a colleague of uses a \tikzstyle def for your requirement, but I can't seem to get this working without separate \draw commands for each portion of your path. You can use the following if you like it.

\documentclass{minimal}

\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{calc,arrows}

\tikzstyle{arrowmid}[0.5]=[decoration=
{markings,
mark=at position #1 with {\arrow{>}}},
postaction={decorate}]

\begin{document}

\begin{tikzpicture}
\draw[arrowmid] (-1,0) -- (0,0);
\draw[arrowmid] (0,0) arc (-180:0:5mm);
\draw[arrowmid] (1,0) -- (2,0);
\end{tikzpicture}

using the 'coordinate' command is sometimes useful

\begin{tikzpicture}[line cap=round]

\coordinate (A) at (0,0);
\coordinate (B) at ($(A)+(1,0)$);
\coordinate (C) at ($(B)+(1,0)$);
\coordinate (D) at ($(C)+(1,0)$);


\draw[arrowmid] (A) -- (B);
\draw[arrowmid] (B) arc (-180:0:5mm);
\draw[arrowmid] (C) -- (D);

\end{tikzpicture}

\end{document}

regards from corporal
vibrovski
2012-04-22 15:54:35 UTC
Permalink
Post by Dox
Dear 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

Continue reading on narkive:
Loading...