7

When I use the tikz-feynman package to draw a Feynman diagram, the PDF output is so strange. It looks like it has been cut. I thought it was because the real center point of the Tikz picture is not what it seems.

\documentclass{standalone} 

\usepackage[compat=1.1.0]{tikz-feynman}
\begin{document}

\begin{tikzpicture}[auto]
    \begin{feynman}
        \feynmandiagram [horizontal=a to b] {
            i1[particle=\(\phi\)] -- [scalar, edge label=\(p_2\)] a -- [anti fermion,edge label=\(p_1\)] i2[particle=$\psi(\lambda_1)$],
            a -- [fermion,momentum=\(p_1+p_2\)] b,
            f1[particle=\(\phi\)] -- [scalar, edge label=\(q_1\)] b -- [fermion,edge label=\(q_2\)] f2[particle=\(\psi(\lambda^\prime_1)\)]
};  
    \end{feynman}
\end{tikzpicture}

\end{document}

enter image description here

I try to change the settings of standalone, like

\documentclass[tikz,border=20pt]{standalone} 

This time it reveals the whole diagram, but it's still not centered? enter image description here

Is there any solution to this?

1 Answer 1

14

Removing the tikzpicture and feynman environments (the stuff with \begin{...} and \end{...}) does the trick. Alternatively, you can keep the environments, then change \feynmandiagram into a simple \diagram to get your desired output. Both methods are shown in the code below.

%!TeX program = LuaLaTeX
\documentclass{standalone}
\usepackage[compat=1.1.0]{tikz-feynman}
\begin{document}

% Both of these methods produce the same output
% Choose the one you like better

% --------------------------------------------------------------
% Method 1
\feynmandiagram [horizontal=a to b] {
  i1[particle=\(\phi\)] -- [scalar, edge label=\(p_2\)] a -- [anti fermion,edge label=\(p_1\)] i2[particle=$\psi(\lambda_1)$],
  a -- [fermion,momentum=\(p_1+p_2\)] b,
  f1[particle=\(\phi\)] -- [scalar, edge label=\(q_1\)] b -- [fermion, edge label=\(q_2\)] f2[particle=\(\psi(\lambda^\prime_1)\)]
};

% --------------------------------------------------------------
% Method 2
\begin{tikzpicture}
\begin{feynman}
  \diagram [horizontal=a to b] {
    i1[particle=\(\phi\)] -- [scalar, edge label=\(p_2\)] a -- [anti fermion,edge label=\(p_1\)] i2[particle=$\psi(\lambda_1)$],
    a -- [fermion,momentum=\(p_1+p_2\)] b,
    f1[particle=\(\phi\)] -- [scalar, edge label=\(q_1\)] b -- [fermion,edge label=\(q_2\)] f2[particle=\(\psi(\lambda^\prime_1)\)]
  };
\end{feynman}
\end{tikzpicture}

\end{document}

You can see your output fits into a single standalone page now:

Feynman diagram with the correction to make the entire diagram appear on the page

So, why didn't your original code work the way it was supposed to? It turns out, the definition of the \feynmandiagram macro creates both a tikzpicture and feynman environment. However, because your \feynmandiagram was already inside these environments, LaTeX was essentially putting a set of tikzpicture and feynman environment inside another set of tikzpicture and feynman diagrams. This probably explains why you saw the center of the diagram not being where it seemed—that was the center point of the inner tikzpicture, but the standalone package was shaping the page based on the box size of the outer tikzpicture.

5
  • thank you! It helps a lot!
    – Meng. G
    Commented Jun 22, 2023 at 7:12
  • 1
    Never put a tikzpicture inside another tikzpicture. The results can be odd. Commented Jun 22, 2023 at 11:28
  • @JohnKormylo your comment helped to set me on the right track for finding why my code worked and the OP's code didn't; thanks! I've edited my answer accordingly.
    – gz839918
    Commented Jun 22, 2023 at 19:59
  • 1
    @Meng.G I'm glad you found this helpful! If you're satisfied with this solution, I'd be grateful if you could mark my answer as Accepted by clicking the check mark (below the voting buttons).
    – gz839918
    Commented Jun 22, 2023 at 20:00
  • See also tex.stackexchange.com/questions/47377/…
    – Rmano
    Commented Jun 22, 2023 at 20:36

You must log in to answer this question.

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