My question is inspired by Feynman Diagrams with tikz.

The photon line (TikZ snake) in the answer does not look like it usually looks on a Feynman diagram: in the "reference" look, which may be obtained using the feynmp package, waves start and finish in the middle of the "wave" (one may check the difference compiling the answer given). Inside the metapost code this is realized in a dumb but effective way: it takes a line and adds "waves" based on the line length. First it computes the (integer) number of waves to put on a line to make length of one as close as possible to some given number, then it computes the length of one wave and finally draws them. The Metapost code is rather short and simple.

Is there a way to fully reproduce this feynmp behaviour in TikZ?

  • Can you point out where in the metapost code this calculation is done? I'm having trouble to find it and would appreaciate the help. – Mafra Dec 1 '12 at 20:50
up vote 22 down vote accepted

Here's a new decoration, complete sines, that does what you describe: It computes the number of full waves that would fit into a given path with a specified wavelength, and then stretches the wavelength so that the path can be completely filled:


\pgfdeclaredecoration{complete sines}{initial}
        next state=sine,
        persistent precomputation={\pgfmathsetmacro\matchinglength{
            \pgfdecoratedinputsegmentlength / int(\pgfdecoratedinputsegmentlength/\pgfdecorationsegmentlength)}
            \setlength{\pgfdecorationsegmentlength}{\matchinglength pt}
        }] {}

    every path/.style={
            complete sines,
            segment length=1cm,
\draw (0,0) -- (2,0);
\draw [yshift=-1.2cm] (0,0) -- (2.5,0);
\draw [yshift=-2.4cm] (0,0) -- (3,0);

Here's an example of three paths, 2 cm, 2.5 cm and 3 cm in length, with a nominal wavelength of 1 cm. In the first case, there are two full waves with a wavelength of 1 cm, in the second there are two full waves with a wavelength of 1.25 cm, and in the third there are three full waves with a wavelength of 1 cm.

If you'd use it in the example you linked to, like this:

gluon/.style={decorate, draw=black,
        decoration={complete sines,amplitude=8pt, segment length=11pt}}

it would yield this

  • Thank you very much. I tried to do similar trick, but this decoration declaration was too tricky for me. – Misha Aug 14 '11 at 15:55
  • @Jake: How can this be modified for a coil decoration? It would also be great to have the option to start and finish pointing up or down. – AndyS Jun 21 '12 at 17:11
  • @AndyS: There already is a version of this decoration that ends either pointing up or down: The coil decoration would take a bit of work, it's probably best to open a new question for that. – Jake Jun 21 '12 at 17:19

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.