[Tex/LaTex] Length of external lines in feynman diagrams (TikZ)

tikz-feynman

I would like to make the following diagram

IDontUnderstandWhyThisFigureGetsBlackWhenItIsResized

using TikZ (The above diagram was done using feynmf package). So far I have written this:

\documentclass[12pt]{article}
\usepackage[compat=1.1.0]{tikz-feynman}

\begin{document}
\begin{tikzpicture}
    \feynmandiagram [ horizontal=i to v1] {
    i -- [double] v1 -- [double] v2 -- [double] v3 -- [double] v1,
    v2 -- [double] o1,
    v3 -- [double] o2,
};
\end{tikzpicture}
\end{document}

and obtained this

diagram2

However, I can't figure out, how to decrease the length of the external lines. In addition, I can't figure out how to make lines crossed like in the first figure. Any suggestions?

Best Answer

If you are going to use the automatic placement algorithms in TikZ-Feynman (CTAN), then unfortunately there's no straightforward way of shortening the external lines as the underlying algorithm has no idea of which lines are external.

It is possible to tweak how far the edges are drawn with shorten <=(distance) and shorten >=(distance) (the difference being whether it cuts off the start of the end); but this only affects the drawing of the edge and not the way the algorithm treats the edge length and as a result I would not really recommend using this. In particular, this will look weird if used in conjunction with the particle style as text will be a long way away from the end of the line.

In your case, a neat way of achieving the desired result is to take advantage of the simple geometry:

\RequirePackage{luatex85}
\documentclass[tikz,border=10pt]{standalone}
\usepackage[compat=1.1.0]{tikz-feynman}

\begin{document}
\begin{tikzpicture}
  \begin{feynman}
    \vertex (i);
    \vertex [right=2cm of i] (center);
    \pgfmathsetmacro\vert{2 * sin(2 * pi / 6 r)};
    \pgfmathsetmacro\horz{2 * cos(2 * pi / 6 r)}
    \vertex [above right=\vert cm and \horz cm of center] (o1);
    \vertex [below right=\vert cm and \horz cm of center] (o2);
    \vertex (v1) at ($(center)!0.7!(i)$);
    \vertex (v2) at ($(center)!0.7!(o1)$);
    \vertex (v3) at ($(center)!0.7!(o2)$);

    \diagram* [edges=double] {
      (i) -- (v1) -- (v2) -- (v3) -- (v1),
      (v2) -- (o1),
      (v3) -- (o2),
    };
  \end{feynman}
\end{tikzpicture}
\end{document}

output

This initially places all of the outer vertices 2cm from the center vertex. It then places each v1, v2 and v3 vertices at 0.7 of the distance between the center and the desired outer vertex.

I realize this solution is very specific to the layout above and is not general at all. More generally though, you can tweak the distances in the above right=(distance) and (distance) of (vertex). There are plenty of other examples that make use of this on this website, and there are examples of this within the documentation for TikZ-Feynman itself.

As for the second part of your question regarding the perpendicular lines crossing the various propagators, this is best achieved using a custom style which itself defines a new custom decoration:

\RequirePackage{luatex85}
\documentclass[tikz,border=10pt]{standalone}
\usepackage[compat=1.1.0]{tikz-feynman}

\tikzfeynmanset{
  crossed/.style={
    /tikz/postaction={
      /tikz/decoration={
        show path construction,
        lineto code={
          \coordinate (tmp1) at ($(\tikzinputsegmentfirst)!5pt!(\tikzinputsegmentlast)$);
          \draw
          ($(tmp1)!4pt!90:(\tikzinputsegmentlast)$)
          -- ($(tmp1)!4pt!-90:(\tikzinputsegmentlast)$);
        },
      },
      /tikz/decorate=true,
    },
  },
  crossed'/.style={
    /tikz/postaction={
      /tikz/decoration={
        show path construction,
        lineto code={
          \coordinate (tmp1) at ($(\tikzinputsegmentlast)!5pt!(\tikzinputsegmentfirst)$);
          \draw
          ($(tmp1)!4pt!90:(\tikzinputsegmentlast)$)
          -- ($(tmp1)!4pt!-90:(\tikzinputsegmentlast)$);
        },
      },
      /tikz/decorate=true,
    },
  },
}

\begin{document}
\begin{tikzpicture}
  \begin{feynman}
    \vertex (i);
    \vertex [right=2cm of i] (center);
    \pgfmathsetmacro\vert{2 * sin(2 * pi / 6 r)};
    \pgfmathsetmacro\horz{2 * cos(2 * pi / 6 r)}
    \vertex [above right=\vert cm and \horz cm of center] (o1);
    \vertex [below right=\vert cm and \horz cm of center] (o2);
    \vertex (v1) at ($(center)!0.7!(i)$);
    \vertex (v2) at ($(center)!0.7!(o1)$);
    \vertex (v3) at ($(center)!0.7!(o2)$);

    \diagram* [edges=double] {
      (i) -- (v1) -- [crossed] (v2) -- [crossed] (v3) -- [crossed'] (v1),
      (v2) -- [crossed] (o1),
      (v3) -- [crossed] (o2),
    };
  \end{feynman}
\end{tikzpicture}
\end{document}

output

The postaction ensures that what follows (in this case the decoration) is drawn on top. We then tell it to draw a decoration in the postaction, and the decoration type is show path construction.

This decoration is a specialized kind of decoration which gives access to \tikzinputsegmentfirst and \tikzinputsegmentlast, and allows for arbitrary code to be executed. In this case, we create a temporary coordinate 5pt away from the start and call it tmp1, and we then draw a straight line that is 8pt long at a 90 degree angle to the original path going through tmp1. For convenience, I have also defined a complementary style crossed' which places the tmp1 coordinate 5pt away from the end.

Related Question