JP-Ellis / tikz-feynman

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

How do I force several nodes on a horizontal line? #26

Closed linwaytin closed 8 years ago

linwaytin commented 8 years ago

Hi,

I must say this package is amazing! It makes things much easier than other packages.

I have several nodes and I want to put them on a horizontal line. If there are only two, I know I can use the option horizontal=a to b. But I actually have more than 2. Is there any easy way to handle this?

Thank you, Wei

JP-Ellis commented 8 years ago

I'm glad you find Ti_k_Z-Feynman useful!

You can use the layered layout option to produce straight lines. The default spring layout is much more optimized for layouts that branch out more, whereas the layered layout imposes a much more rigid structure.

For example:

\documentclass[tikz, border=10pt, convert]{standalone}

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

\begin{document}
\feynmandiagram [layered layout, horizontal=a to b] {
  a -- [boson] b -- [fermion] c -- [gluon] d,
};
\end{document}

produces: output

The documentation has examples of more complicated diagrams which also use the layered layout, and otherwise you can also have a look at the TikZ Manual for a more thorough explanation of the layered layout algorithm.

linwaytin commented 8 years ago

Thank you for your answer.

In fact, my problem is a little tricky. I need to put some self-energy lines on the horizontal line.

\documentclass[tikz, border=10pt, convert]{standalone}
\usepackage[compat=1.1.0]{tikz-feynman}

\begin{document}
\feynmandiagram [layered layout, horizontal=b to c] {
  a -- [fermion] b -- [fermion] c -- [fermion] d,
  e -- [scalar] b,
  e -- [scalar] c,
};
\end{document}

I want to make a, b, c, and d on a horizontal line. The above code can't do that.

JP-Ellis commented 8 years ago

Is that what you want?

\documentclass[tikz, border=10pt, convert]{standalone}
\usepackage[compat=1.1.0]{tikz-feynman}

\begin{document}
\feynmandiagram [layered layout, horizontal=b to c] {
  a -- [fermion] b -- [fermion] c -- [fermion] d,
  c -- [scalar, half left] b,
};
\end{document}

26

linwaytin commented 8 years ago

Not exactly. I want a vertex and two straight edges. It seems I have to specify positions of all points?

JP-Ellis commented 8 years ago

I'm not sure why you want a vertex there, unless it attaches to other things. Anyway, it probably is easiest to add this extra vertex manually as follows:

\documentclass[tikz, border=10pt, convert]{standalone}
\usepackage[compat=1.1.0]{tikz-feynman}

\begin{document}
\begin{tikzpicture}
  \begin{feynman}
    \diagram [layered layout, horizontal=b to c] {
      a -- [fermion] b -- [fermion] c -- [fermion] d,
    };
    \vertex (s) at ($(b)!0.5!(c) - (0, 1cm)$);
    \draw [scalar] (b) -- (s) -- (c);
  \end{feynman}
\end{tikzpicture}
\end{document}

26

linwaytin commented 8 years ago

This graph is used in my research. Indeed, it is unusual.

Thank you so much for answering my question.