5

I want to put a tikz graph (a Feynman diagram using tikz-feynman) inside other tikz nodes, but it doesn't seem to work. A MWE is below. It has to be compiled with lualatex as I'm using graphs.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{graphs}
\usepackage[compat=1.1.0]{tikz-feynman}

\begin{document}
\tikzset{
  box/.pic={
    \feynmandiagram[inner,horizontal=a to d]{
      a -- [fermion] b -- [fermion] c -- [fermion] d -- [draw=none]
      e -- [fermion] f -- [fermion] g -- [fermion] h -- [draw=none] a,
      b -- [boson] g, c -- [boson] f,
    };
  }
}

\begin{tikzpicture}
  \graph [clockwise=4,radius=5em]{
    % a/{B}, b/{\tikz{\pic {box};}}, c/{C}, d/{f}  %% <-- what I want to do
    a/{B}, b/{box}, c/{C}, d/{f}
  };
  \graph {
    (a) -> {(b), (d)}, {(b), (d)} -> (c)
  };
\end{tikzpicture}

\end{document}

PS: I also found out tikz-feynman does not work with the standalone document class after I had wasted a few hours!

EDIT: Thanks to @TorbjørnT., the above issues is due to standalone, and is resolved by starting with \RequirePackage{luatex85}.

  • 1
    tikz-feynman works fine with standalone, but standalone doesn't work with lualatex. To fix that, add \RequirePackage{luatex85} just before \documentclass{standalone} – Torbjørn T. Sep 24 '17 at 21:29
  • @TorbjørnT. Thanks a lot! I'll try it out in the morning – suvayu Sep 24 '17 at 21:33
6

Nesting tikzpictures isn't something you can always count on working, and you're nesting three levels deep. \feynmandiagram starts a tikzpicture, \tikz is a shortform of \begin{tikzpicture} .. \end{tikzpicture}, and you're placing the first inside the second inside a third tikzpicture.

An alternative that does work is to use a savebox.

Note that you don't actually need \usepackage{tikz} \usetikzlibrary{graphs} as tikz-feynman loads both.

output of code

\RequirePackage{luatex85}
\documentclass{standalone}
\usepackage[compat=1.1.0]{tikz-feynman}
\newsavebox{\foo}
\savebox{\foo}{
\feynmandiagram[horizontal=a to d]{
      a -- [fermion] b -- [fermion] c -- [fermion] d -- [draw=none]
      e -- [fermion] f -- [fermion] g -- [fermion] h -- [draw=none] a,
      b -- [boson] g, c -- [boson] f,
    };}
\begin{document}

\begin{tikzpicture}
  \graph [clockwise=4,radius=10em]{
     a/{B}, b/\usebox{\foo}, c/{C}, d/{f} 
  };
  \graph {
    (a) -> {(b), (d)}, {(b), (d)} -> (c)
  };
\end{tikzpicture}
\end{document}
  • (+1) ... and should count on never working :-) – cfr Sep 24 '17 at 22:53
  • This works very well. I wanted to avoid nesting in the first place, but didn't know how to go about it. Thank you! – suvayu Sep 25 '17 at 3:45

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.