Background
When labels are shown with feynmp, they extend beyond the box of the graph. One can use \fmfframe
to allocate an invisible frame to accommodate these, but it seems like you need to manually adjust all of the parameters.
Question
Is there an easy way of automatically placing ones Feynman graphs in an appropriate frame?
Specifically, I would like to be able to use graphs naturally in equations with minimal manual intervention. The following example works, but has the following issues:
- I use
\raisebox{-0.5\height}{}
to vertically center the graph, but this does not quite work properly. How do I fix this? -
One can use
\fmfframe(<left>,<top>)(<right>,<bottom>){}
to "pad" the graph, but the only way I can see to get these values is to manually adjust (using a frame with\fbox
so I can see what I am doing).Note: All the numbers in
()
are in terms of the\unitlength
defined byfeynmp
(default is1pt
). - One ugly "feature" of
\fmfframe
is that is precludes blank lines in its argument (which can be useful for spacing out one's graph definitions). Any easy fix?
Here is a minimal working example:
\documentclass{minimal}
\usepackage{feynmp}
% Needed to interpret generated *.1, *.2 etc. as ps files.
\DeclareGraphicsRule{*}{mps}{*}{}
\setlength{\fboxsep}{0pt}
\begin{document}
\begin{fmffile}{fgraphs}
\begin{equation}
5\times
\raisebox{-0.5\height}{ % 1: center vertically -- does not quite work.
\fbox{ % Draw fram so we can tweak the fmfframe
\fmfframe(5,17)(20,17){ % 2: Had to manually guess these.
\begin{fmfgraph*}(40,30)
% Note that the size is given in normal parentheses
% instead of curly brackets in units of \unitlength
% (1pt by default)
\fmfleft{i1,i2} % Define external vertices from bottom to top
\fmfright{o1,o2}
\fmf{fermion}{i1,v1,o1}
\fmf{fermion}{i2,v2,o2}
\fmf{photon,tension=0.3}{v1,v2}
% 3: Blank lines not allowed in fmfframe!
\fmflabel{$\vec{p}$}{i1}
\fmflabel{$\vec{q}$}{i2}
\fmflabel{$\vec{p}+\vec{k}$}{o1}
\fmflabel{$\vec{p}-\vec{k}$}{o2}
\end{fmfgraph*}
}
}
}
= 5i V_k.
\end{equation}
\end{fmffile}
\end{document}
Compile this with:
pdflatex tst
mpost fgraphs
pdflatex tst
pdflatex tst
to get:
Best Answer
Without knowing anything about the
feynmp
or METAPOST, I removed thefbox
and I just tried to put everyting in a TikZ node. Then I did the centering with respect to the baseline of the bounding box of thetikzpicture
and the result is centered. So remaining question is, How robust is this?, and I have no clue. But seemingly, there is no bad box complaints etc. I regret that it's up to you and other proficient METAPOST users to test and try to break this.Because I don't know anything I can also try stupid things such as putting the
fmffile
environment completely inside the node in other words, nest it inside thetikzpicture
. And that gives the same result. But I feel that the second one is more robust.Coming back to the manual guessing of the parameters of the
\fmfframe
, I can see that if you omit the manually set lines, the bounding box only covers the drawing but not thep,q,p+k
etc. vectors. Hence I just put a invisible rectangle to set the bounding box enlarged by2.5ex
. Not a wonderful solution but gives you at least a prediction power how much is left out. So I just chose to have2.5ex
since I know that only a letter with an arrow is sticking out.As you can see from the image below, I forgot to take into account the horizontal effect so the equal sign is a little to the left than where it should have been. If there is a handle on the bounding box of the Feynman drawing, TikZ can do centering and all other fancy things with ease. Otherwise at least you don't have to recompile the Feynman drawing since the bounding box computation is now on TikZ side and easier to tune since you only add extra shifts instead of hard coding numbers.