JP-Ellis / tikz-feynman

Feynman Diagrams with TikZ
http://www.jpellis.me/projects/tikz-feynman
Other
146 stars 20 forks source link

Use baseline while no proper node at hand #42

Closed Turgon-Aran-Gondolin closed 6 years ago

Turgon-Aran-Gondolin commented 6 years ago

In some diagrams such as a box diagram, we have

\feynmandiagram[horizontal=i1 to f1,layered layout,inline=(d.base)]{
    i1 -- [fermion] a -- [fermion] b -- [fermion] f1,
    i2 -- [fermion] c -- [fermion] d -- [fermion] f2,
    { [same layer] a -- [photon] c},
    { [same layer] b-- [photon] d},
  };

but as you can see, there's no node in the center (i.e. in the middle of a and c), so how can I set the baseline in there? Do you have any idea? Thanks a lot.

JP-Ellis commented 6 years ago

The easiest is to automatically calculate the centre. As you said, you want the middle of a and c which can be computed by TikZ. The format for that is ($(a)!0.5!(c)$). The dollar signs here indicate that this is a computer node that is half-way (0.5) between a and c.

\RequirePackage{luatex85}
\documentclass[border=10pt]{standalone}

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

\begin{document}
ABC \feynmandiagram[horizontal=i1 to f1,layered layout,inline=($(a)!0.5!(c)$)]{
    i1 -- [fermion] a -- [fermion] b -- [fermion] f1,
    i2 -- [fermion] c -- [fermion] d -- [fermion] f2,
    { [same layer] a -- [photon] c},
    { [same layer] b-- [photon] d},
}; XYZ
\end{document}

test-1