# Tikz, decorations

I use tikz as a general purpose drawing package because of its flexibility etc... I need to draw some Feynman diagrams like these:

I tried to draw arc like

\begin{tikzpicture}
\draw [decorate, decoration={snake}] (0,0) arc (180:0:2);
\end{tikzpicture}


but the result is ugly looking:

Other question

but

1) I tried to compile and the result was different:

2) As you can see in the first image I posted, I need arbitrary angle arc and, in the solution presented in the link, it seems possible to draw only semicircles

3) The code is not elegant at all: in particular, using this solution drawing a solid e arc or a snakeish arc requires complete different source code.

I was thinking if it is possible simply to stop the arc when it reaches the specified (final) angle, without any regard to the decoration.

• It is not a duplicate because: 1) The solution given in the link you posted tried to reproduce only the "snake" decoration (for other decoration it would be more complicate) 2) It doesn't work if you try to draw an arc. – MaPo Jul 27 '14 at 14:22
• – cfr Jul 27 '14 at 14:48
• I read that post, but unfortunately, the result is not good looking – MaPo Jul 27 '14 at 14:57
• Could you clarify the "not good looking" means to you? The images you posted look fine to me, but then maybe I'm not seeing what you see. – A.Ellett Jul 27 '14 at 17:49

All the three Feynman diagrams shown in the question can be realized with a few lines of code using the new TikZ-Feynman package (see also the project page).

Here is the code to produce all of them. You must compile with lualatex in order to take advantage of the automatic positioning of the vertices.

\documentclass[tikz]{standalone}
\usepackage{tikz-feynman}
\tikzfeynmanset{compat=1.0.0}
\begin{document}
% first diagram
\feynmandiagram [layered layout, horizontal=a to d] {
a [particle=$$\mu$$] -- [photon] b [dot],
b -- [anti fermion, half left, edge label=$$k$$] c [dot] --
[half left, fermion, edge label=$$k + q$$] b,
c -- [photon] d [particle=$$\nu$$],
};

% second diagram
\feynmandiagram [layered layout, horizontal=a to d] {
a -- b [dot] -- [fermion,edge label'=$$p + k$$] c [dot] -- d [particle=$$p$$],
b -- [photon, half left, edge label=$$k$$] c,
};

% third diagram
\begin{tikzpicture}
\begin{feynman}
\vertex (a) {$$\mu$$};
\vertex [right=of a] (b);
\vertex [above right=of b] (u1);
\vertex [above right=of u1] (u2) {$$p'$$};
\vertex [below right=of b] (d1);
\vertex [below right=of d1] (d2) {$$p$$};

\diagram*{
(a) -- [photon, edge label'=$$q$$] (b),
(b) -- [fermion, edge label=$$k+q$$] (u1) -- [fermion] (u2),
(b) -- [anti fermion, edge label'=$$k$$] (d1) -- [anti fermion] (d2),
(d1) -- [photon, half right, edge label'=$$p - k$$] (u1),
};
\end{feynman}
\end{tikzpicture}
\end{document}


Just for fun, with feynmp and egreg's feynmp-auto. If on MikTeX or TeX Live 2012 or earlier, compile with --shell-escape (or --enable-write18) as command-line options. All manual positioning (\fmfforce commands) is done to match your sample, but the positions can be computed automatically by leaving these out.

\documentclass{standalone}
\usepackage{feynmp-auto}

\begin{document}
\unitlength = 2mm
\begin{fmffile}{testing}
\begin{fmfgraph*}(30,20)
\fmfleft{i} \fmfright{o}
\fmflabel{$p$}{o}
\fmf{plain}{i,v1} \fmf{plain}{v2,o}
\fmf{fermion,label=$p+k$}{v1,v2}
\fmf{photon,left,label=$k$}{v1,v2}
\fmfdot{v1,v2}
\fmfforce{(0.3w,0.5h)}{v1}
\fmfforce{(0.6w,0.5h)}{v2}
\fmfforce{(0.9w,0.5h)}{o}
\end{fmfgraph*}
\end{fmffile}
\end{document}


• Why not \usepackage{feynmp-auto} that avoids the need of \DeclareGraphicsRule and of redefining \endfmffile? ;-) By the way, since the release of TeX Live 2013, -shell-escape is not needed for running mpost. – egreg Jul 28 '14 at 7:48
• @egreg, thanks for that! I did not know about your feynmp-auto until now. – Paul Gessler Jul 28 '14 at 12:27
• My hope was to learn ONE package that would allow me to get every diagram (Feynman and not Feynman) I wanted. Tikz seemed to me a package like the one I wanted. But evidently it is not... The think that astonish me more is that even \draw[decorate, decoration={snake, segment legth=5mm, post length=0mm}] (0,0) -- (0,2); does not produce the intuitive result (at the end of the wavy line there is a straight segment... this let me think that, at least decorations library is a bit buggy) – MaPo Jul 28 '14 at 14:47
• @MaPo well, this is metapost, so you could learn it and do all your other figures with metapost. Alternatively, Feynman diagrams can be done with pstricks or asymptote (both shown here), which can also be used for more general figures/diagrams. And it is certainly possible with tikz as well. Each package has its advantages and disadvantages for different graphics needs. – Paul Gessler Jul 28 '14 at 15:00
• @Paul Gessler: I knew, as a matter of facts, I asked how to get good-looking (or if you prefer not-ugly-looking) Feynman graph with Tikz, and I've no received any answer yet... – MaPo Jul 28 '14 at 17:47

Another solution with tikz, as requested. The problem with the linked answer is that the arguments to the atan function in the pgf low-level layer have been reversed. Switching the arguments inside the wavy semicircle definition solves that issue.

Code for the styles borrowed from here.

\documentclass{standalone}
\usepackage{tikz}

\usetikzlibrary{positioning,arrows.meta}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{calc}

% adapted from https://tex.stackexchange.com/a/160358/21344; changed photon style
\tikzset{
fermion/.style={draw=black, postaction={decorate},decoration={markings,mark=at position .55 with {\arrow{Latex}}}},
vertex/.style={draw,shape=circle,fill=black,minimum size=2pt,inner sep=0pt},
photon/.style={wavy semicircle,wave amplitude=0.3mm,wave count=10}
}

% adapted from https://tex.stackexchange.com/a/89003/21344; swapped atan args
\newif\ifmirrorsemicircle
\tikzset{
wave amplitude/.initial=0.2cm,
wave count/.initial=8,
mirror semicircle/.is if=mirrorsemicircle,
mirror semicircle=false,
wavy semicircle/.style={
to path={
let \p1 = (\tikztostart),
\p2 = (\tikztotarget),
\n1 = {veclen(\y2-\y1,\x2-\x1)},
\n2 = {atan2(\x2-\x1,\y2-\y1))} in
plot [
smooth,
samples=(\pgfkeysvalueof{/tikz/wave count}+0.5)*8+1, % Calculate the number of samples needed, so the samples are in sync with the wave and fall on the extrema
domain=0:1,
shift={($(\p1)!0.5!(\p2)$)}
] ({ % Polar coordinates: Angle...
(\x*180-\n2 + 180 + \ifmirrorsemicircle 1 \else -1 \fi * 90%
(%
\n1/2+\pgfkeysvalueof{/tikz/wave amplitude} * %
sin(
\x * 360 * (\pgfkeysvalueof{/tikz/wave count} + 0.5%
)%
)%
})
} (\tikztotarget)
}
}

\begin{document}
\begin{tikzpicture}
\coordinate (i);
\coordinate[vertex, right=of i] (v1);
\coordinate[vertex, right=of v1] (v2);
\coordinate[right=of v2] (o);
\draw (i) -- (v1);
\draw[fermion] (v1) -- (v2) node[midway,below] {$p+k$};
\draw[photon] (v1) to (v2);
\path (v1) to[in=90,out=90] node[above=2mm]{$k$} (v2); % ghost path for label
\draw (v2) -- (o) node[right] {$p$};
\end{tikzpicture}
\end{document}


Personally, I feel that feynmp is much better suited for these uses. Knowing how to use a hammer really well doesn't make it a good tool for sawing.

• Thank you, for your patience. I totally agree with you: feynmp is much better suited for Feynman graph – MaPo Jul 29 '14 at 17:52