3

I am using tikz-feynman to draw Feynman diagram which align as 2x2 subfigure.

However, the position of figure and subfigure compare with caption is very strange as in picture

My result

This is part of my code

\documentclass[12pt,a4paper,titlepage]{book}
\usepackage{tikz-feynman}
\usepackage{subcaption}
\begin{document}
\begin{figure}
\begin{subfigure}{0.5\textwidth}
\centering
\begin{tikzpicture}
\feynmandiagram[large, horizontal=a to b]{
i1[particle=\(\overline d\)]--[fermion]a--[fermion, edge label'=\(\alpha\),momentum=\(p+k\)]b--[fermion, momentum=\(p\)]f1[particle=\(s\)],
i2[particle=\(\overline s\)]--[anti fermion, momentum'=\(p\)]c--[anti fermion, edge label=\(\beta\), rmomentum'=\(k\)]d--[anti fermion]f2[particle=\(d\)],
{[same layer]a--[photon, edge label=\(W\), rmomentum'=\(p+k\)]c},
{[same layer]b--[photon, edge label'=\(W\), momentum=\(k\)]d},
};
\end{tikzpicture}
\caption{}
\end{subfigure}%
\begin{subfigure}{.5\textwidth}
\centering
  \begin{tikzpicture}
\feynmandiagram[large, horizontal=a to b]{
i1[particle=\(\overline d\)]--[fermion]a--[fermion, edge label'=\(\alpha\),momentum=\(p+k\)]b--[fermion, momentum=\(p\)]f1[particle=\(s\)],
i2[particle=\(\overline s\)]--[anti fermion, momentum'=\(p\)]c--[anti fermion, edge label=\(\beta\), rmomentum'=\(k\)]d--[anti fermion]f2[particle=\(d\)],
{[same layer]a--[photon, edge label=\(W\), rmomentum'=\(p+k\)]c},
{[same layer]b--[scalar, edge label'=\(H\), momentum=\(k\)]d},
};
\end{tikzpicture}
\caption{}
\end{subfigure}\\
\begin{subfigure}{.5\textwidth}
  \fbox{
\begin{tikzpicture}
\feynmandiagram[large, horizontal=a to b]{
i1[particle=\(\overline d\)]--[fermion]a--[fermion, edge label'=\(\alpha\),momentum=\(p+k\)]b--[fermion, momentum=\(p\)]f1[particle=\(s\)],
i2[particle=\(\overline s\)]--[anti fermion, momentum'=\(p\)]c--[anti fermion, edge label=\(\beta\), rmomentum'=\(k\)]d--[anti fermion]f2[particle=\(d\)],
{[same layer]a--[scalar, edge label=\(H\), rmomentum'=\(p+k\)]c},
{[same layer]b--[scalar, edge label'=\(H\), momentum=\(k\)]d},
};
\end{tikzpicture}}
\caption{}
\end{subfigure}%
\begin{subfigure}{.5\textwidth}
  \begin{tikzpicture}
\feynmandiagram[large, horizontal=a to b]{
i1[particle=\(\overline d\)]--[fermion]a--[fermion, edge label'=\(\alpha\),momentum=\(p+k\)]b--[fermion, momentum=\(p\)]f1[particle=\(s\)],
i2[particle=\(\overline s\)]--[anti fermion, momentum'=\(p\)]c--[anti fermion, edge label=\(\beta\), rmomentum'=\(k\)]d--[anti fermion]f2[particle=\(d\)],
{[same layer]a--[scalar, edge label=\(H\), rmomentum'=\(p+k\)]c},
{[same layer]b--[photon, edge label'=\(W\), momentum=\(k\)]d},
};
\end{tikzpicture}
\caption{}
\end{subfigure}
\caption{Box diagram}
\end{figure}
\end{document}

How to solve this one?

Thanks.

  • Your code snippet looks ok to me, so I guess the problem lies somewhere either before, after or at the dots. It can for example depend on the document class, included packets or how you have written the figures. As it given now it is more a guessing game to say where. Please, extend the code to a minimal compilable example, starting with \documentclass and ending with \end{document}, in such a way that it clearly shows the problem. Then it is possible to dig deeper to see what is going on, and you can get an answer. – StefanH Nov 4 '16 at 8:15
  • @StefanH I have added all of my packages already. – Natthawin Cho Nov 4 '16 at 9:09
  • 1
    The minimal working example should be a fully fledged but minimal example that replicates the issue; I should be able to copy-paste it into a new file and see the error. Unfortunately, what you have provided is not minimal (there are packages used which aren't relevant), nor is it working (it lacks \begin{document} and \end{document}. I have tried recreating the issue on my end, but to no avail. – JP-Ellis Nov 4 '16 at 10:34
  • @JP-Ellis I have edited already. – Natthawin Cho Nov 4 '16 at 10:40
3

Firstly, I'd like to say that it's really great to see the package I created being put to good use! These diagrams look great :D

Now, about the issue you were having, it was because you have:

\begin{tikzpicture}
  \feynmandiagram {...};
\end{tikzpicture}

The \feynmandiagram command actually creates its own TikZ environment and thus should not be used within a {tikzpicture} environment. You are creating TikZ pictures within TikZ pictures which is generally not a good idea. The intent of \feynmandiagram is that it is a standalone command just for Feynman diagrams.

If you wanted to add more fancy annotations in TikZ, or have the Feynman diagrams as just one component of a larger TikZ picture, or even need to place vertices manually, then the procedure is:

\begin{tikzpicture}
  <other TikZ commands>
  \begin{feynman}
    \diagram {...};
    <other Feynman and/or TikZ commands>
  \end{feynman}
  <other TikZ commands>
\end{tikzpicture}

Notice that there is an additional {feynman} environment inside the {tikzpicture} and the command for the diagram is \diagram and not \feynmandiagram.

So, here is your fixed MWE:

\documentclass[12pt,a4paper,titlepage]{book}

\usepackage{tikz-feynman}
\usepackage{subcaption}

\begin{document}
\begin{figure}
  \centering
  \begin{subfigure}[t]{0.49\textwidth}
    \centering
    \feynmandiagram [large, horizontal=a to b] {
      i1 [particle=\(\overline d\)]
        -- [fermion] a
        -- [fermion, edge label'=\(\alpha\), momentum=\(p+k\)] b
        -- [fermion, momentum=\(p\)] f1[particle=\(s\)],
      i2 [particle=\(\overline s\)]
        -- [anti fermion, momentum'=\(p\)] c
        -- [anti fermion, edge label=\(\beta\), rmomentum'=\(k\)] d
        -- [anti fermion] f2 [particle=\(d\)],
      {[same layer]
        a -- [photon, edge label=\(W\), rmomentum'=\(p+k\)] c
      },
      {[same layer]
        b -- [photon, edge label'=\(W\), momentum=\(k\)] d
      },
    };
    \caption{\(WW\) box diagram}
  \end{subfigure}
  \begin{subfigure}[t]{0.49\textwidth}
    \centering
    \feynmandiagram [large, horizontal=a to b] {
      i1 [particle=\(\overline d\)]
        -- [fermion]a--[fermion, edge label'=\(\alpha\), momentum=\(p+k\)] b
        -- [fermion, momentum=\(p\)]f1[particle=\(s\)],
      i2 [particle=\(\overline s\)]
        -- [anti fermion, momentum'=\(p\)] c
        -- [anti fermion, edge label=\(\beta\), rmomentum'=\(k\)] d
        -- [anti fermion] f2 [particle=\(d\)],
      {[same layer]
        a -- [photon, edge label=\(W\), rmomentum'=\(p+k\)] c
      },
      {[same layer]
        b -- [scalar, edge label'=\(H\), momentum=\(k\)] d
      },
    };
    \caption{\(WH\) box diagram}
  \end{subfigure}
  \newline
  \begin{subfigure}{0.49\textwidth}
    \feynmandiagram [large, horizontal=a to b] {
      i1 [particle=\(\overline d\)]
        -- [fermion]a--[fermion, edge label'=\(\alpha\),momentum=\(p+k\)] b
        -- [fermion, momentum=\(p\)]f1[particle=\(s\)],
      i2 [particle=\(\overline s\)]
        -- [anti fermion, momentum'=\(p\)] c
        -- [anti fermion, edge label=\(\beta\), rmomentum'=\(k\)] d
        -- [anti fermion]f2[particle=\(d\)],
      {[same layer]
        a -- [scalar, edge label=\(H\), rmomentum'=\(p+k\)] c
      },
      {[same layer]
        b -- [scalar, edge label'=\(H\), momentum=\(k\)] d
      },
    };
    \caption{\(HH\) box diagram}
  \end{subfigure}
  \begin{subfigure}{0.49\textwidth}
    \feynmandiagram [large, horizontal=a to b] {
      i1 [particle=\(\overline d\)]
        -- [fermion] a
        -- [fermion, edge label'=\(\alpha\), momentum=\(p+k\)] b
        -- [fermion, momentum=\(p\)] f1 [particle=\(s\)],
      i2[particle=\(\overline s\)]
        -- [anti fermion, momentum'=\(p\)] c
        -- [anti fermion, edge label=\(\beta\), rmomentum'=\(k\)] d
        -- [anti fermion] f2 [particle=\(d\)],
      {[same layer]
        a -- [scalar, edge label=\(H\), rmomentum'=\(p+k\)] c
      },
      {[same layer]
        b -- [photon, edge label'=\(W\), momentum=\(k\)] d
      },
    };
    \caption{\(HW\) box diagram}
  \end{subfigure}
  \caption{Box diagram}
\end{figure}
\end{document}

output

Just a small remark, you can use spaces and newlines to make the code a little more legible; TikZ-Feynman (and TikZ) don't really care (much).

  • Thanks for answering my question!!! Your package is really cool and useful. I think I have to use it for a long time :) – Natthawin Cho Nov 4 '16 at 14:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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