Drawing a scattering Feynman diagram with TikZ

I am trying to produce a scattering diagram with TikZ but I have become stuck.

The Desired Structure

I am trying to achieve this layout of lines, including their arrow directions. In my diagram.

Minimum Working Example

\documentclass[11pt]{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{trees}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{decorations.markings}

\begin{document}

\tikzset{
photon/.style={decorate, decoration={snake}, draw=red},
particle/.style={draw=blue, postaction={decorate},
decoration={markings,mark=at position .5 with {\arrow[draw=blue]{>}}}},
antiparticle/.style={draw=blue, postaction={decorate},
decoration={markings,mark=at position .5 with {\arrow[draw=blue]{<}}}},
gluon/.style={decorate, draw=black,
decoration={coil,amplitude=4pt, segment length=5pt}}
}

\begin{tikzpicture}[
thick,
% Set the overall layout of the tree
level/.style={level distance=1.5cm},
level 2/.style={sibling distance=3.5cm},
]
\coordinate
child[grow=down]{
edge from parent [antiparticle]
child {
node{$E$}
edge from parent [particle]
}
child {
node{$D$}
edge from parent [gluon]
}
node [above=3pt] {$C$}
}
% I have to insert a dummy child to get the tree to grow
% correctly to the right.
child[grow=right, level distance=0pt] {
child {
node{$A$}
edge from parent [gluon]
}
child {
node{$B$}
edge from parent [particle]
}
};
\end{tikzpicture}

\end{document}


Output

So far, I have the basic structure, except one of my lines is 'wandering'. The one that's labelled $A$ should be 'reflected' from where it is by 180 degrees.

Edit

Using @GonzaloMedina's approach, and with his helpful suggestion to the TikZ lirary, I found I can get the following diagram, which is very close to what I wanted:

\begin{document}
\tikzset{
particle/.style={thick,draw=blue, postaction={decorate},
decoration={markings,mark=at position .5 with {\arrow[blue]{triangle 45}}}},
gluon/.style={decorate, draw=black,
decoration={coil,aspect=0}}
}
\tikzset{
particle/.style={thin,draw=blue, postaction={decorate},
decoration={markings,mark=at position .5 with {\arrow[blue]{stealth}}}},
gluon/.style={decorate, draw=black, decoration={snake=coil}}
}

\begin{tikzpicture}[node distance=1cm and 1.5cm]
\coordinate[label=left:$G$] (e1);
\coordinate[below right=of e1] (aux1);
\coordinate[above right=of aux1,label=right:$N$] (e2);
\coordinate[below=1.25cm of aux1] (aux2);
\coordinate[below left=of aux2,label=left:$N$] (e3);
\coordinate[below right=of aux2,label=right:$G$] (e4);

\draw[gluon] (e1) -- (aux1);
\draw[particle] (aux1) -- (e2);
\draw[particle] (e3) -- (aux2);
\draw[gluon] (aux2) -- (e4);
\draw[particle] (aux2) -- node[label=right:$N$] {} (aux1);
\end{tikzpicture}
\end{document}


I looked in the TikZ manual (on page 95) and found how to make a coil (like a spring), but it didn't seem to work.

-
Why do you use grow=right instead of grow=up (and switching the children)? That being said, I think the tikz-cd package might be something you would be interested in, although your picture seems to be about chemistry. How complex do these kind of diagrams get? Maybe a plain-TikZ approach would be easier. –  Qrrbrbirlbel Mar 30 '13 at 15:08
@Qrrbrbirlbel It's not chemistry but particle physics. ;-) nevertheless would I also suggest a plain-TikZ approach instead of somehow modified TikZ-trees. –  Benedikt Bauer Mar 30 '13 at 15:59
@BenediktBauer I should have read the title and not only the body of the question where Feynman hasn’t come up once. :) –  Qrrbrbirlbel Mar 30 '13 at 16:15
–  m0nhawk Mar 30 '13 at 16:52
@Qrrbrbirlbel I was using a template from texample.net –  User 17670 Mar 30 '13 at 20:32
add comment

3 Answers

One possibility: instead of a tree, I just used some coordinates and decorated paths; I used the triangle 45 arrow tip from the arrows library, changed the gluon style to use decoration={coil,aspect=0}, and suppressed parts of the original code not relevant here:

\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{positioning,arrows}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{decorations.markings}

\begin{document}

\tikzset{
particle/.style={thick,draw=blue, postaction={decorate},
decoration={markings,mark=at position .5 with {\arrow[blue]{triangle 45}}}},
gluon/.style={decorate, draw=black,
decoration={coil,aspect=0}}
}

\begin{tikzpicture}[node distance=1cm and 1.5cm]
\coordinate[label=left:$e^{-}$] (e1);
\coordinate[below right=of e1] (aux1);
\coordinate[above right=of aux1,label=right:$e^{-}$] (e2);
\coordinate[below=1.25cm of aux1] (aux2);
\coordinate[below left=of aux2,label=left:$e^{-}$] (e3);
\coordinate[below right=of aux2,label=right:$e^{-}$] (e4);

\draw[particle] (e1) -- (aux1);
\draw[particle] (aux1) -- (e2);
\draw[particle] (e3) -- (aux2);
\draw[particle] (aux2) -- (e4);
\draw[gluon] (aux1) -- node[label=right:$\gamma$] {} (aux2);
\end{tikzpicture}
\end{document}


After an edit to the question, here's some new code with the required coil decoration:

\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{positioning,arrows}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{decorations.markings}

\begin{document}
\tikzset{
particle/.style={thick,draw=blue, postaction={decorate},
decoration={markings,mark=at position .5 with {\arrow[blue]{triangle 45}}}},
gluon/.style={decorate, draw=black,
decoration={coil,aspect=0.3,segment length=3pt,amplitude=3pt}}
}

\begin{tikzpicture}[node distance=1cm and 1.5cm]
\coordinate[label=left:$G$] (e1);
\coordinate[below right=of e1] (aux1);
\coordinate[above right=of aux1,label=right:$N$] (e2);
\coordinate[below=1.25cm of aux1] (aux2);
\coordinate[below left=of aux2,label=left:$N$] (e3);
\coordinate[below right=of aux2,label=right:$G$] (e4);

\draw[gluon] (e1) -- (aux1);
\draw[particle] (aux1) -- (e2);
\draw[particle] (e3) -- (aux2);
\draw[gluon] (aux2) -- (e4);
\draw[particle] (aux2) -- node[label=right:$N$] {} (aux1);
\end{tikzpicture}
\end{document}


-
TeX beast! Thanks a lot! Do you know how I can get coils - as in the ones on p.95 of the TikZ documentation (see question edit)? –  User 17670 Mar 30 '13 at 20:47
@User17670 You're welcome. However, page 95 of the current pgfmanual doesn't show any coils. Please add to your question (a link to) an image showing the desired type of coil. –  Gonzalo Medina Mar 30 '13 at 20:56
I posted a link to a manual (maybe it's not the most up to date, sorry) at the bottom of my question edit. In terms of what the snake=coil is supposed to look like - it's the one that features in the second image of my question (they look like springs). –  User 17670 Mar 30 '13 at 21:03
@User17670 Ah, now I see. Yes; that manual is outdated. Now I know what you want. Please see my updated answer (in 40 seconds). –  Gonzalo Medina Mar 30 '13 at 21:08
@User17670 answer updated; here you can find the updated manual mirrors.ctan.org/graphics/pgf/base/doc/generic/pgf/… . On page 323 you can find the attributes for the coil decoration. –  Gonzalo Medina Mar 30 '13 at 21:11
show 2 more comments

You can also use the feynMP package to create Feynman diagrams. It uses metapost instead of tikz, but provides a nice interface for creating different types of Feynman diagrams. For example:

\documentclass{article}
\usepackage{feynmp}
\DeclareGraphicsRule{*}{mps}{*}{}

\begin{document}
\unitlength = 1mm
\begin{fmffile}{gluon}
\begin{fmfgraph*}(40,30)
\fmfleft{i1,i2}
\fmflabel{$e^{-}$}{i1}
\fmflabel{$e^{-}$}{i2}
\fmfright{o1,o2}
\fmflabel{$e^{-}$}{o1}
\fmflabel{$e^{-}$}{o2}
\fmf{fermion, fore=blue}{i1,v1,o1}
\fmf{fermion, fore=blue}{i2,v2,o2}
\fmf{photon,label=$\gamma$}{v1,v2}
\fmfdot{v1,v2}
\end{fmfgraph*}
\end{fmffile}
\write18{mpost gluon}
\end{document}


Run this twice with pdflatex --shell-escape filename, and you will get

-
+1 That's a nice output! For me, though, I just got a white space, with no errors. –  User 17670 Mar 30 '13 at 20:34
You need to enable shell escape. Otherwise run pdflatex, run metapost gluon, and then run pdflatex again. –  Aditya Mar 30 '13 at 20:36
add comment

Here is my take on this. I think it produces beautiful output and doesn't require running any special programs like feynmp. Drawback: you have to put in the nodes manually, but that's very managable imho. Bonus: it retains full flexibility for using any kind of tikz decorations and so on while at the same time making it easy to use due to the tree approach.

\documentclass{standalone}

\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{trees}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{decorations.markings}

\begin{document}

% Define styles for the different kind of edges in a Feynman diagram
\tikzset{
gageboson/.style={decorate,decoration={snake},draw=tud9a},
electronin/.style={draw=tud1a,postaction={decorate},decoration={markings,mark=at position .55 with {\arrow[draw=tud1a]{<}}}},
electronout/.style={draw=tud1a,postaction={decorate},decoration={markings,mark=at position .55 with {\arrow[draw=tud1a]{>}}}},
gluon/.style={decorate,draw=magenta,decoration={coil,amplitude=4pt,segment length=5pt}}
}

\begin{tikzpicture}[thick,
% Set the overall layout of the tree
level/.style={level distance=1.2cm},
level 2/.style={sibling distance=2.6cm},
level 3/.style={sibling distance=2cm}
]
\coordinate
child[grow=up]{
child {
node {$k^{'}_{1}$}
edge from parent [electronout]
}
child {
node {$k_1$}
edge from parent [electronin]
}
edge from parent [gageboson] node [right=3pt] {$q$}
}
child[grow=down,level distance=0pt]{
child {
node {$k_{2}$}
edge from parent [electronin]
}
child {
node {$k^{'}_2$}
edge from parent [electronout]
}
};
\fill[black] (0,0) circle (.05cm);
\fill[black] (0,1.2cm) circle (.05cm);
\end{tikzpicture}

\end{document}


Yields:

However, when you look closely, the wriggly line of the phonon is not perfect. Anybody know how to get rid of that linear part?

In the particular case asked above, the code would be:

\documentclass{standalone}

\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{trees}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{decorations.markings}

\begin{document}

% Define styles for the different kind of edges in a Feynman diagram
\tikzset{
gageboson/.style={decorate,decoration={snake},draw=black},
electronin/.style={draw=tud1a,postaction={decorate},decoration={markings,mark=at position .55 with {\arrow[draw=red]{<}}}},
electronout/.style={draw=tud1a,postaction={decorate},decoration={markings,mark=at position .55 with {\arrow[draw=red]{>}}}},
gluon/.style={decorate,draw=magenta,decoration={coil,amplitude=4pt,segment length=5pt}}
}

\begin{tikzpicture}[
thick,
% Set the overall layout of the tree
level/.style={level distance=1.5cm},
level 2/.style={sibling distance=2.6cm},
level 3/.style={sibling distance=2cm}
]
\coordinate
child[grow=up]{
child {
node {$N$}
edge from parent [electronout]
}
child {
node {$G$}
edge from parent [gageboson]
}
edge from parent [electronout] node [right=3pt] {$N$}
}
child[grow=down,level distance=0pt]{
child {
node {$N$}
edge from parent [electronin]
}
child {
node {$G$}
edge from parent [gageboson]
}
};
\fill[black] (0,0) circle (.05cm);
\fill[black] (0,1.5cm) circle (.05cm);
\end{tikzpicture}

\end{document}


and results in this

-
(Once the vote cap passes) Nice answer. I can clearly see the pictures :P By the way, the special program you mention is the mighty MetaPost. So that's not quite an external special program but a monster that is created together with TeX :) Though I'm a die-hard TikZ user, I don't think anybody can discard MetaPost via TikZ. –  percusse Apr 12 '13 at 22:14
Thanks for the flowers! One reason to use my approach over others using MetaPost is that writeLaTeX for example does - to my knowledge - not support the --shell-escape option. Now everything is contained within TikZ. Plus, it should compile faster. –  Meferdati Apr 15 '13 at 2:12
add comment