19

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

The Desired Structure

enter image description here

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

enter image description here

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}

enter image description here

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.

5
  • 1
    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. Mar 30, 2013 at 15:08
  • 1
    @Qrrbrbirlbel It's not chemistry but particle physics. ;-) nevertheless would I also suggest a plain-TikZ approach instead of somehow modified TikZ-trees. Mar 30, 2013 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. :) Mar 30, 2013 at 16:15
  • 2
  • @Qrrbrbirlbel I was using a template from texample.net
    – User 17670
    Mar 30, 2013 at 20:32

4 Answers 4

13
+50

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}

enter image description here

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}

enter image description here

7
  • 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, 2013 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. Mar 30, 2013 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, 2013 at 21:03
  • 1
    @User17670 Ah, now I see. Yes; that manual is outdated. Now I know what you want. Please see my updated answer (in 40 seconds). Mar 30, 2013 at 21:08
  • 1
    @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. Mar 30, 2013 at 21:11
11

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

enter image description here

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

These diagrams are very easy to produce with the new tikz-feynman package (see also the project page), based on this answer. The only requirement for using automatic positioning of the vertices is to compile the document with lualatex:

\documentclass[tikz]{standalone}
\usepackage[compat=1.1.0]{tikz-feynman}
\begin{document}
\feynmandiagram [vertical=b to a] {
  i1 [particle=\(\textup{e}^{-}\)] -- [fermion] a -- [fermion] i2 [particle=\(\textup{e}^{-}\)],
  a -- [photon,edge label'=\(\gamma\)] b,
  f1 [particle=\(\textup{e}^{-}\)] -- [fermion] b -- [fermion] f2 [particle=\(\textup{e}^{-}\)],
};

\tikzfeynmanset{
  every fermion={draw=blue},
}
\feynmandiagram [vertical=b to a] {
  i1 [particle=\(N\)] -- [fermion] a,
  i2 [particle=\(G\)] -- [photon] a,
  a  -- [fermion,edge label'=\(N\)] b,
  b  -- [photon] f1 [particle=\(G\)],
  b  -- [fermion] f2 [particle=\(N\)],
};
\end{document}

enter image description here

enter image description here

1
  • I'm the author of TikZ-Feynman! It's amazing to see it being used. Thanks @giordano!
    – JP-Ellis
    Feb 4, 2016 at 11:34
3

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: resulting graphic

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 answer

3
  • 1
    (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, 2013 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, 2013 at 2:12
  • Since 2012 the --shell-escape should not be needed for MetaPost any more since TeXLive considers it a “safe” program now. Jul 4, 2015 at 7:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .