Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to put two feynman diagrams side by side, but they get displayed below eachother. I am using feynmf and subfloat. This normally works for pictures.

\begin{figure}[ht!]
      \centering
    \subfloat{

        \begin{fmfgraph*}(40, 25)
        \fmfstraight
         \fmfbottom{wm,i2,z2}
          \fmftop{wp,i1,z1}
          \fmf{dashes}{wp,i1,z1}
          \fmf{dashes}{z2,i2,wm}
          \fmf{dashes,caption=$W^{+}$}{i1,i2}
        %  \fmf{dashes,caption=$Z^0$}{i2,z1}
         % \fmf{dashes,caption=$Z^0$}{i2,z2}
        \fmfv{lab=$Z^0$}{z1}
        \fmfv{lab=$Z^0$}{z2}
    \fmfv{lab=$W^+$}{wp}
    \fmfv{lab=$W^-$}{wm}
        \end{fmfgraph*}
    }

    \subfloat{

        \begin{fmfgraph*}(40, 25)
        \fmfstraight
         \fmfbottom{wm,i2,z2}
          \fmftop{wp,i1,z1}
          \fmf{dashes}{wp,i1,z1}
          \fmf{dashes}{z2,i2,wm}
          \fmf{dashes,caption=$W^{+}$}{i1,i2}
        %  \fmf{dashes,caption=$Z^0$}{i2,z1}
         % \fmf{dashes,caption=$Z^0$}{i2,z2}
        \fmfv{lab=$Z^0$}{z1}
        \fmfv{lab=$Z^0$}{z2}
    \fmfv{lab=$W^+$}{wp}
    \fmfv{lab=$W^-$}{wm}
        \end{fmfgraph*}
    }

    \caption{Exchange of W boson}
    \end{figure}
share|improve this question
4  
Don't leave blank lines between the \subfloats –  egreg Jan 25 '12 at 17:34
1  
I'd also recommend you provide a minimal example. A lot is not clear for people who never use fmfgraph*. For example, which packages should they include.... –  Marc van Dongen Jan 25 '12 at 17:50
    
I didn't know that problem was unrelated to fmfgraph. I'll try and make better examples next time. –  Ben Ruijl Jan 26 '12 at 10:43
add comment

1 Answer

up vote 10 down vote accepted

As @egreg said in the comments, the reason why the second figure is below is due to the blank line.

There is a very good reason for this. Recall that in text mode a blank line signals the beginning of a new paragraph and subsequent text is placed below. So, the following will place the words next to each other:

One
Two

but the following will place the words below each other:

One

Two

Same goes for pictures, there are just boxes as far as TeX is concerned, not much different from letters, words, paragraphs, etc....

The MWE below produces the image on the left, but if you insert a blank line you get the image on the right:

enter image description here enter image description here

Note:

  • My rule of thumb is not to use blank lines unless I am trying to indicate a new paragraph. For readability you can insert a comment line as long as the first non-blank character is a %. Note that it does not need to be at the beginning of the line as in the MWE below.

Code:

Since this problem is not related to feynmf, I simply used pgfplots to generate the figures:

\documentclass{article}
\usepackage{pgfplots}
\usepackage{subfig}

\begin{document}
\begin{figure}[ht!]
    \centering
    \subfloat{
        \begin{tikzpicture}
        \begin{axis}[height=3cm]
        \end{axis}
        \end{tikzpicture}
    }
    % A blank line here like a new paragraph so next picture is placed below
    \subfloat{
        \begin{tikzpicture}
        \begin{axis}[height=3cm]
        \end{axis}
        \end{tikzpicture}
    }

    \caption{Exchange two subfloats}
    \end{figure}
\end{document}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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