5

I am trying to create a custom vertex in a TikZ-Feynman diagram that is a rectangle with a cross (Γ—) inside it. The goal is to use this for visualizing operator counterterms. I want the rectangle to have a border and to display the cross inside it, without the cross overwriting or obscuring the rectangle.

I know tikz-feynman does not define such a vertex, but I was wondering if there was some way to do it.

I have tried the following code:

\documentclass{article}
\usepackage{tikz}
\usepackage[compat=1.1.0]{tikz-feynman}
\usetikzlibrary{shapes}

\begin{document}

\begin{tikzpicture}
  \begin{feynman}
    % Custom vertex
    \vertex [draw, shape=rectangle, cross out] (v0) at (0, 0) {};
    
    % Other vertices
    \vertex (a) at (-2,1);
    \vertex (b) at (-2,-1);
    \vertex (c) at (2,0);

    \diagram* {
      (a) -- [fermion] (v0) -- [fermion] (b),
      (v0) -- [photon] (c),
    };
  \end{feynman}
\end{tikzpicture}

\end{document}

However, this results in the cross overwriting the rectangle, and the cross does not appear correctly inside the shape. I am expecting the cross to be inside the rectangle without obscuring the border.

Can someone please help me achieve this?

3 Answers 3

6

You could copy the definition of the crossed circle from tikz-feynman and replace the circle with a square:

% !TeX TS-program = lualatex -interaction=nonstopmode % | txs:///view-pdf | txs:///view-log

\documentclass{article}
\usepackage{tikz}
\usepackage[compat=1.1.0]{tikz-feynman}
\usetikzlibrary{shapes}

\makeatletter
\pgfdeclareshape{crossed square}
{
  \inheritsavedanchors[from=rectangle]
  \inheritanchorborder[from=rectangle]
  \inheritanchor[from=rectangle]{north}
  \inheritanchor[from=rectangle]{north west}
  \inheritanchor[from=rectangle]{north east}
  \inheritanchor[from=rectangle]{center}
  \inheritanchor[from=rectangle]{west}
  \inheritanchor[from=rectangle]{east}
  \inheritanchor[from=rectangle]{mid}
  \inheritanchor[from=rectangle]{mid west}
  \inheritanchor[from=rectangle]{mid east}
  \inheritanchor[from=rectangle]{base}
  \inheritanchor[from=rectangle]{base west}
  \inheritanchor[from=rectangle]{base east}
  \inheritanchor[from=rectangle]{south}
  \inheritanchor[from=rectangle]{south west}
  \inheritanchor[from=rectangle]{south east}

  \inheritbackgroundpath[from=rectangle]

  \foregroundpath{
    \pgfpathmoveto{\pgfpointadd{\southwest}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}
    \pgfpathlineto{\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
    \pgfpathmoveto{\pgfpointadd{\northeast\pgf@xa=\pgf@x\southwest    \pgf@x=\pgf@xa}{\pgfpoint{-\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}
    \pgfpathlineto{\pgfpointadd{\southwest\pgf@xa=\pgf@x\northeast\pgf@x=\pgf@xa}{\pgfpointscale{-1}{\pgfpoint{-\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}  
 }
}
\makeatother

\begin{document}

\begin{tikzpicture}
  \begin{feynman}
    % Custom vertex
    \vertex [draw, shape=crossed square] (v0) at (0, 0) {};
    
    % Other vertices
    \vertex (a) at (-2,1);
    \vertex (b) at (-2,-1);
    \vertex (c) at (2,0);

    \diagram* {
      (a) -- [fermion] (v0) -- [fermion] (b),
      (v0) -- [photon] (c),
    };
  \end{feynman}
\end{tikzpicture}

\end{document}

enter image description here

Same works with a cross inside the square:

% !TeX TS-program = lualatex -interaction=nonstopmode % | txs:///view-pdf | txs:///view-log

\documentclass{article}
\usepackage{tikz}
\usepackage[compat=1.1.0]{tikz-feynman}
\usetikzlibrary{shapes}

\makeatletter
\pgfdeclareshape{crossed square}
{
  \inheritsavedanchors[from=rectangle]
  \inheritanchorborder[from=rectangle]
  \inheritanchor[from=rectangle]{north}
  \inheritanchor[from=rectangle]{north west}
  \inheritanchor[from=rectangle]{north east}
  \inheritanchor[from=rectangle]{center}
  \inheritanchor[from=rectangle]{west}
  \inheritanchor[from=rectangle]{east}
  \inheritanchor[from=rectangle]{mid}
  \inheritanchor[from=rectangle]{mid west}
  \inheritanchor[from=rectangle]{mid east}
  \inheritanchor[from=rectangle]{base}
  \inheritanchor[from=rectangle]{base west}
  \inheritanchor[from=rectangle]{base east}
  \inheritanchor[from=rectangle]{south}
  \inheritanchor[from=rectangle]{south west}
  \inheritanchor[from=rectangle]{south east}

  \inheritbackgroundpath[from=rectangle]

  \foregroundpath{
    \pgfpathmoveto{\pgfpointadd{\southwest}{\pgfpoint{3\pgfkeysvalueof{/pgf/outer xsep}}{3\pgfkeysvalueof{/pgf/outer ysep}}}}
    \pgfpathlineto{\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{3\pgfkeysvalueof{/pgf/outer xsep}}{3\pgfkeysvalueof{/pgf/outer ysep}}}}}
    \pgfpathmoveto{\pgfpointadd{\northeast\pgf@xa=\pgf@x\southwest    \pgf@x=\pgf@xa}{\pgfpoint{-3\pgfkeysvalueof{/pgf/outer xsep}}{3\pgfkeysvalueof{/pgf/outer ysep}}}}
    \pgfpathlineto{\pgfpointadd{\southwest\pgf@xa=\pgf@x\northeast\pgf@x=\pgf@xa}{\pgfpointscale{-1}{\pgfpoint{-3\pgfkeysvalueof{/pgf/outer xsep}}{3\pgfkeysvalueof{/pgf/outer ysep}}}}}  
 }
}
\makeatother

\begin{document}

\begin{tikzpicture}
  \begin{feynman}
    % Custom vertex
    \vertex [draw, shape=crossed square] (v0) at (0, 0) {};
    
    % Other vertices
    \vertex (a) at (-2,1);
    \vertex (b) at (-2,-1);
    \vertex (c) at (2,0);

    \diagram* {
      (a) -- [fermion] (v0) -- [fermion] (b),
      (v0) -- [photon] (c),
    };
  \end{feynman}
\end{tikzpicture}

\end{document}

enter image description here

1
  • Ah, this is what I tried also, but I didn't know how to modify the "\foregroundpath" part. Commented yesterday
6

Here is one of the numerous ways to solve your problem.

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

\begin{document}

\begin{tikzpicture}
  \begin{feynman}
    % Step 1: Draw a rectangle node
    \vertex [
      draw,
      shape=rectangle,
      minimum size=4mm, % Controls size of the box
      thick    
    ] (v0) at (0, 0) {};

    % Step 2: Draw the 'Γ—' symbol inside the rectangle using diagonals
    % Diagonals trimmed so they don't stick out
    \draw [thick, shorten >=0.5pt, shorten <=0.5pt]
          (v0.north west) -- (v0.south east);
    \draw [thick, shorten >=0.5pt, shorten <=0.5pt]
          (v0.north east) -- (v0.south west); 

    % Other vertices
    \vertex (a) at (-2,1);
    \vertex (b) at (-2,-1);
    \vertex (c) at (2,0);

    % Connect with diagram
    \diagram* {
      (a) -- [fermion] (v0) -- [fermion] (b),
      (v0) -- [photon] (c),
    };
  \end{feynman}
\end{tikzpicture}

\end{document}

enter image description here

P.S. After reflecting on Sebastiano’s remark (see the comment below), I have decided after all to prevent the cross from sticking out of the square, especially since it is easy to do by adding the appropriate options to \draw. By the way, this also lets you make the X smaller and thus fit it inside the square. Just replace 0.5pt with, say, 3pt.

Edit
If the cross should be inside the square, the code can be slightly modified.

\documentclass{article}
\usepackage{tikz}
\usepackage[compat=1.1.0]{tikz-feynman}
\usetikzlibrary{calc} %%%%%%%%%%%%%

\begin{document}

\begin{tikzpicture}
  \begin{feynman}    
    \vertex [draw, shape=rectangle, minimum size=4mm] (v0) at (0, 0) {};
    
    \draw [thick]
      ($ (v0.north west)!0.2!(v0.south east) $) -- ($ (v0.south east)!0.2!(v0.north west) $)
      ($ (v0.north east)!0.2!(v0.south west) $) -- ($ (v0.south west)!0.2!(v0.north east) $);

    \vertex (a) at (-2,1);
    \vertex (b) at (-2,-1);
    \vertex (c) at (2,0);

    \diagram* {
      (a) -- [fermion] (v0) -- [fermion] (b),
      (v0) -- [photon] (c),
    };
  \end{feynman}
\end{tikzpicture}

\end{document}

enter image description here

3
  • Just a suggestion for first code. Do you have seen the vertices of the square? The cross goes outside. Commented 2 days ago
  • 1
    @Sebastiano thank you. Of course, I noticed that the cross slightly extends outside, which is why I suggested another version with the cross inside. But since the OP is silent and it's not entirely clear what exactly is needed, I left both options. Commented 2 days ago
  • Kind kabenyuk, it's OK now. Anyway, I had already voted positively for your answer. Commented yesterday
4

Here another example with the fermion that end on the vertex of the square.

enter image description here

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

% New style: square with cross
\tikzset{
  square crossed dot/.style={
    draw=black,
    minimum size=0.5cm,
    shape=rectangle,
    fill=white,
    inner sep=0pt,
    line width=0.5pt,
    path picture={
      \draw
        (path picture bounding box.north west) -- (path picture bounding box.south east)
        (path picture bounding box.south west) -- (path picture bounding box.north east);
    }
  }
}
\begin{document}
\begin{tikzpicture}
\begin{feynman}
\node[square crossed dot] (0) at (2, 2);  % Here a personalized square with X
\vertex (1) at (0, 4);
\vertex (2) at (0, 0);
\vertex (5) at (6, 2);

\diagram*{
    (1) --[fermion] (0),
    (2) --[fermion] (0),
    (0) --[photon] (5)
};
\end{feynman}
\end{tikzpicture}
\end{document}

Just to be fair, I would like to inform you that if you increase the magnification, you will see some empty spaces, as indicated by the red arrows.

enter image description here

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.