There is also the background library
(not sure which version of PDF/TikZ this arrived in, it's in PGF2.10). From the manual (section 25 in PGF2.10):
This library defines "backgrounds" for pictures. This does not refer to background pictures, but rather to frames drawn around and behind pictures.
It then gives various examples, from drawing a grid behind a picture to drawing a rectangle. In the simplest case, we can just supply the option framed
to the tikzpicture
environment to get a simple rectangular frame. Using the background rectangle
style, we can make it a little more fancy (though as the manual says, no-one in their right mind would use this particular framing).
Code:
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}[framed]
\draw (0,0) circle (2);
\draw (0,0) rectangle (3,2);
\end{tikzpicture}
\bigskip
\begin{tikzpicture}[framed,background rectangle/.style={double,ultra thick,draw=red, top color=blue, rounded corners}]
\draw (0,0) circle (2);
\draw (0,0) rectangle (3,2);
\end{tikzpicture}
\end{document}
Picture:
There are, of course, several options to change the background, in particular to change how far from the picture the frame is. See Section 25 of the manual (2.10 version) for details.
The node
won't work because you have used ;
in your \semiloop
definition. Actually
\semiloop[fermion]{v2}{v3}{0} node[midway,above=0.1cm] {$f$};
will expand to
\draw[fermion] let \p1 = ($(v3)-(v2)$) in (v3) arc (0:({0+180}):({0.5*veclen(\x1,\y1)});) node[midway,above=0.1cm] {$f$};
i.e., node
without \
(\node
). You can redefine the command like this with the help of xparse
package:
\NewDocumentCommand\semiloop{O{black}mmmO{}O{above}}
{%
\draw[#1] let \p1 = ($(#3)-(#2)$) in (#3) arc (#4:({#4+180}):({0.5*veclen(\x1,\y1)})node[midway, #6] {#5};)
}
%% Syntax
%\semiloop[fermion][<draw options>]{<first node>}{<second node>}{<angle>}[<label>][<below, default: above>];
Full code:
\documentclass{article}
\usepackage{pgfplots}
\usepackage{xparse}
\usetikzlibrary{positioning,arrows,patterns}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{calc}
\tikzset{
photon/.style={decorate, decoration={snake}, draw=black},
fermion/.style={draw=black, postaction={decorate},decoration={markings,mark=at position .55 with {\arrow{>}}}},
vertex/.style={draw,shape=circle,fill=black,minimum size=3pt,inner sep=0pt},
}
\NewDocumentCommand\semiloop{O{black}mmmO{}O{above}}
{%
\draw[#1] let \p1 = ($(#3)-(#2)$) in (#3) arc (#4:({#4+180}):({0.5*veclen(\x1,\y1)})node[midway, #6] {#5};)
}
%% Syntax
%\semiloop[fermion][<draw options>]{<first node>}{<second node>}{<angle>}[<label>][<below, default: above>];
\begin{document}
\begin{tikzpicture}[node distance=1cm and 1cm]
\coordinate[vertex] (v1);
\coordinate[vertex, right=of v1] (v2);
\coordinate[vertex, right=of v2] (v3);
\coordinate[vertex, right=of v3] (v4);
\coordinate[above right=of v4,label=right:$f$] (f1);
\coordinate[below right=of v4,label=right:$f$] (f2);
\coordinate[above left =of v1,label=left :$e^+$] (e1);
\coordinate[below left =of v1,label=left :$e^-$] (e2);
\draw[fermion] (e1) -- (v1);
\draw[fermion] (v1) -- (e2);
\draw[photon] (v1) -- (v2) node[midway,above=0.1cm] {$Z$};
\draw[photon] (v3) -- (v4) node[midway,above=0.1cm] {$Z$};
\draw[fermion] (f1) -- (v4);
\draw[fermion] (v4) -- (f2);
% the next two lines are causing the mess
\semiloop[fermion]{v2}{v3}{0}[$f$];
\semiloop[fermion]{v3}{v2}{180}[$\bar{f}$][below];
\end{tikzpicture}
\begin{tikzpicture}[node distance=1cm and 1cm]
\coordinate[vertex] (v1);
\coordinate[vertex, right=of v1] (v2);
\coordinate[vertex, right=of v2] (v3);
\coordinate[vertex, right=of v3] (v4);
\coordinate[above right=of v4,label=right:$f$] (f1);
\coordinate[below right=of v4,label=right:$f$] (f2);
\coordinate[above left =of v1,label=left :$e^+$] (e1);
\coordinate[below left =of v1,label=left :$e^-$] (e2);
\draw[fermion] (e1) -- (v1);
\draw[fermion] (v1) -- (e2);
\draw[photon] (v1) -- (v2) node[midway,above=0.1cm] {$Z$};
\draw[photon] (v3) -- (v4) node[midway,above=0.1cm] {$Z$};
\draw[fermion] (f1) -- (v4);
\draw[fermion] (v4) -- (f2);
% the next two lines behave fine, but don't have any labels
\semiloop[fermion]{v2}{v3}{0};
\semiloop[fermion]{v3}{v2}{180};
\end{tikzpicture}
\end{document}
It looks like you need an update for your tex distribution. Add \listfiles
and compare yours (you can find it in your log file at the end) with following:
*File List*
article.cls 2007/10/19 v1.4h Standard LaTeX document class
size10.clo 2007/10/19 v1.4h Standard LaTeX file (size option)
pgfplots.sty 2013/10/03 v1.9 Data Visualization (1.9)
tikz.sty 2013/12/13 v3.0.0 (rcs-revision 1.142)
pgf.sty 2013/12/18 v3.0.0 (rcs-revision 1.14)
pgfrcs.sty 2013/12/20 v3.0.0 (rcs-revision 1.28)
everyshi.sty 2001/05/15 v3.00 EveryShipout Package (MS)
pgfrcs.code.tex
pgfcore.sty 2010/04/11 v3.0.0 (rcs-revision 1.7)
graphicx.sty 1999/02/16 v1.0f Enhanced LaTeX Graphics (DPC,SPQR)
keyval.sty 1999/03/16 v1.13 key=value parser (DPC)
graphics.sty 2009/02/05 v1.0o Standard LaTeX Graphics (DPC,SPQR)
trig.sty 1999/03/16 v1.09 sin cos tan (DPC)
graphics.cfg 2007/01/18 v1.5 graphics configuration of teTeX/TeXLive
pdftex.def 2011/05/27 v0.06d Graphics/color for pdfTeX
infwarerr.sty 2010/04/08 v1.3 Providing info/warning/error messages (HO)
ltxcmds.sty 2011/11/09 v1.22 LaTeX kernel commands for general use (HO)
pgfsys.sty 2013/11/30 v3.0.0 (rcs-revision 1.47)
pgfsys.code.tex
pgfsyssoftpath.code.tex 2013/09/09 (rcs-revision 1.9)
pgfsysprotocol.code.tex 2006/10/16 (rcs-revision 1.4)
xcolor.sty 2007/01/21 v2.11 LaTeX color extensions (UK)
color.cfg 2007/01/18 v1.5 color configuration of teTeX/TeXLive
pgfcore.code.tex
pgfcomp-version-0-65.sty 2007/07/03 v3.0.0 (rcs-revision 1.7)
pgfcomp-version-1-18.sty 2007/07/23 v3.0.0 (rcs-revision 1.1)
pgffor.sty 2013/12/13 v3.0.0 (rcs-revision 1.25)
pgfkeys.sty
pgfkeys.code.tex
pgfmath.sty
pgfmath.code.tex
pgffor.code.tex
tikz.code.tex
xparse.sty 2013/12/31 v4634 L3 Experimental document command parser
expl3.sty 2014/01/07 v4646 L3 Experimental code bundle wrapper
l3names.sty 2014/01/04 v4640 L3 Namespace for primitives
l3bootstrap.sty 2014/01/04 v4640 L3 Experimental bootstrap code
etex.sty 1998/03/26 v2.0 eTeX basic definition package (PEB)
l3basics.sty 2014/01/04 v4642 L3 Basic definitions
l3expan.sty 2014/01/04 v4642 L3 Argument expansion
l3tl.sty 2013/12/27 v4625 L3 Token lists
l3seq.sty 2013/12/14 v4623 L3 Sequences and stacks
l3int.sty 2013/08/02 v4583 L3 Integers
l3quark.sty 2013/12/14 v4623 L3 Quarks
l3prg.sty 2014/01/04 v4642 L3 Control structures
l3clist.sty 2013/07/28 v4581 L3 Comma separated lists
l3token.sty 2013/08/25 v4587 L3 Experimental token manipulation
l3prop.sty 2013/12/14 v4623 L3 Property lists
l3msg.sty 2013/07/28 v4581 L3 Messages
l3file.sty 2013/10/13 v4596 L3 File and I/O operations
l3skip.sty 2013/07/28 v4581 L3 Dimensions and skips
l3keys.sty 2013/12/08 v4614 L3 Experimental key-value interfaces
l3fp.sty 2014/01/04 v4642 L3 Floating points
l3box.sty 2013/07/28 v4581 L3 Experimental boxes
l3coffins.sty 2013/12/14 v4624 L3 Coffin code layer
l3color.sty 2012/08/29 v4156 L3 Experimental color support
l3luatex.sty 2013/07/28 v4581 L3 Experimental LuaTeX-specific functions
l3candidates.sty 2014/01/06 v4643 L3 Experimental additions to l3kernel
ifpdf.sty 2011/01/30 v2.3 Provides the ifpdf switch (HO)
supp-pdf.mkii
***********
Best Answer
I would go the following way:
(0,0)
,(1.5,1)
, and(4,2)
).So, the code could be
Note that the angles at
(B)
should be carefully choosen so that the curve is smooth at that point. The curve enters (B) at 190 degrees, and leaves it at 10 degrees, so that both directions are colinear.