Can I use \path to draw a line that goes through 2 edges.
Consider:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzstyle{status} = [rectangle, draw=black, text centered, anchor=north, text=black, minimum width=2em, minimum height=2em, node distance=6ex and 7em, font=\bfseries]
\tikzstyle{line} = [draw,thick,-latex]
\tikzstyle{transition} = [font=\small]
\begin{document}
\begin{tikzpicture}
\node [status, fill=green] (T) {H};
\node [status, fill=red, right=4em of T] (A) {A};
\node [status, fill=gray, right=4em of A] (D) {D};
\path [line] (T) -- (A) node[transition,pos=0.5,above,align=left] {$\#A \geq 1$};
\path [line] (A) -- (D) node[transition,pos=0.5,above,align=left] {wait $\tau$ tick\\$\tau\sim\mathcal{G}(\lambda)$};
%\path [line] (D) -| (T) node[transition,pos=0.83,left] {$p_{repl}$};
\end{tikzpicture}
\end{document}
Screenshot:
Mockup of what I want:
Easier than we thought, you can make it substituting the commented line (line number 17) in your code with:
\path [line] (D) -- ++(0,-1) -- +(-4.25,0) -- (T) node[transition,pos=0.3,right] {$p_{repl}$};
The output:
Improvement: even better, using -| and then one aux point only instead of two (one is needed):
\path [line] (D) -- ++(0,-1) -| (T) node [transition,pos=0.8,left] {$p_{repl}$};
Related
I would like to split on multiple lines an equation which contain tikzpicture in gathered environment. I have tried to use align and split environments but both did not work...
Here is a working example where the equation is on one line:
\documentclass[12pt]{article}
\usepackage{amssymb}
% !TEX program = lualatex
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage{tikz}
\usepackage[compat=1.1.0]{tikz-feynman}
\begin{document}
\begin{equation}
2\Im\left(F(q^2)\right) =
\begin{gathered}
\scalebox{0.7}{
\begin{tikzpicture}
\begin{feynman}
\vertex (i1) {\(s\)};
\vertex [right=of i1] (a);
\vertex [right=of a] (b);
\vertex [right=of b] (i2);
\diagram* {
i1 -- a --[half left] b -- i2,
b --[half left, double] a,
};
%% Find the midpoint which is halfway between a and b
\coordinate (midpoint) at ($(a)!0.5!(b)$);
%% Draw a line starting 2 units above the midpoint, and
%% ending 2 units below the midpoints
\draw [dashed] ($(midpoint) + (0, 0.8)$) -- ($(midpoint) + (0,-0.8)$);
\end{feynman}
\end{tikzpicture}
}
\end{gathered}
= \int\frac{\,d^d k}{i\pi^{d/2}} \left[2\pi i\: \theta(k^0)\delta(k^2-m^2)\right]\left[2\pi i\: \theta(q^0-k^0)\delta((q-k)^2)\right]%
\end{equation}
\end{document}
Here is what I would like to do
\documentclass[12pt]{article}
\usepackage{amssymb}
% !TEX program = lualatex
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage{tikz}
\usepackage[compat=1.1.0]{tikz-feynman}
\begin{document}
\begin{equation}
\begin{split}
2\Im\left(F(q^2)\right) &=
\begin{gathered}
\scalebox{0.7}{
\begin{tikzpicture}
\begin{feynman}
\vertex (i1) {\(s\)};
\vertex [right=of i1] (a);
\vertex [right=of a] (b);
\vertex [right=of b] (i2);
\diagram* {
i1 -- a --[half left] b -- i2,
b --[half left, double] a,
};
%% Find the midpoint which is halfway between a and b
\coordinate (midpoint) at ($(a)!0.5!(b)$);
%% Draw a line starting 2 units above the midpoint, and
%% ending 2 units below the midpoints
\draw [dashed] ($(midpoint) + (0, 0.8)$) -- ($(midpoint) + (0,-0.8)$);
\end{feynman}
\end{tikzpicture}
}
\end{gathered}\\
&= \int\frac{\,d^d k}{i\pi^{d/2}} \left[2\pi i\: \theta(k^0)\delta(k^2-m^2)\right]\left[2\pi i\: \theta(q^0-k^0)\delta((q-k)^2)\right]%
\end{split}
\end{equation}
\end{document}
The latter returns a error due to the gathered in the split environment.
Does any of you know to solution to my problem ?
It's unclear to me what your desired result should look like exactly, but I think this should be approximately what you want:
\documentclass[12pt]{article}
\usepackage{amssymb}
% !TEX program = lualatex
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage{tikz}
\usepackage[compat=1.1.0]{tikz-feynman}
\begin{document}
\begin{align}
2\Im\left(F(q^2)\right) &=
\parbox{0.5\linewidth}{%
\scalebox{0.7}{
\begin{tikzpicture}
\begin{feynman}
\vertex (i1) {\(s\)};
\vertex [right=of i1] (a);
\vertex [right=of a] (b);
\vertex [right=of b] (i2);
\diagram* {
i1 -- a --[half left] b -- i2,
b --[half left, double] a,
};
%% Find the midpoint which is halfway between a and b
\coordinate (midpoint) at ($(a)!0.5!(b)$);
%% Draw a line starting 2 units above the midpoint, and
%% ending 2 units below the midpoints
\draw [dashed] ($(midpoint) + (0, 0.8)$) -- ($(midpoint) + (0,-0.8)$);
\end{feynman}
\end{tikzpicture}
}
} \\
&= \int\frac{\,d^d k}{i\pi^{d/2}} \left[2\pi i\: \theta(k^0)\delta(k^2-m^2)\right]\left[2\pi i\: \theta(q^0-k^0)\delta((q-k)^2)\right] \notag
\end{align}
\end{document}
This gives the following result:
I would like to add an arrow from Variable 5 to the middle of the arrow that connects Variable 2 and Variable 3.
\documentclass[jou]{apa7}
\usepackage[american]{babel}
\usetikzlibrary{positioning}
\tikzset{mynode/.style={draw,text width=1.90cm,align=center}
}
\begin{document}
\begin{figure}
\begin{tikzpicture}
\node[mynode] (v1){Variable 1};
\node[mynode,below left=of v1](v2) {Variable 2};
\node[mynode,below right=of v1](v3) {Variable 3};
\node[mynode,below = 2.5cm of v1] (v4){Variable 4};
\node[mynode, above right=of v1](v5) {Variable 5};
\draw[-latex] (v2.north) -- node[auto,] {a} (v1.west);
\draw[-latex] (v1.east) -- node[auto,] {b} (v3.north);
\draw[-latex] (v2.east) -- node[below, align=center] {c} (v3.west);
\draw[-latex] (v2.south) -- node[below=3mm, align=center] {d} (v4.west);
\draw[-latex] (v3.south) -- node[below=3mm, align=center] {e} (v4.east);
\draw[-latex] (v5.south) -- node[auto,]{f} (v3.north);
\end{tikzpicture}
\end{figure}
\end{document}
You can use the calc library to calculate the middle between the nodes v2 and v3:
\documentclass[jou]{apa7}
\usepackage[american]{babel}
\usetikzlibrary{positioning}
\usetikzlibrary{calc}
\tikzset{mynode/.style={draw,text width=1.90cm,align=center}
}
\begin{document}
\begin{figure}
\begin{tikzpicture}
\node[mynode] (v1){Variable 1};
\node[mynode,below left=of v1](v2) {Variable 2};
\node[mynode,below right=of v1](v3) {Variable 3};
\node[mynode,below = 2.5cm of v1] (v4){Variable 4};
\node[mynode, above right=of v1](v5) {Variable 5};
\draw[-latex] (v2.north) -- node[auto,] {a} (v1.west);
\draw[-latex] (v1.east) -- node[auto,] {b} (v3.north);
\draw[-latex] (v2.east) -- node[below, align=center] {c} (v3.west);
\draw[-latex] (v2.south) -- node[below=3mm, align=center] {d} (v4.west);
\draw[-latex] (v3.south) -- node[below=3mm, align=center] {e} (v4.east);
\draw[-latex] (v5.south) -- node[auto,]{f} (v3.north);
\draw[-latex] (v5.south) -- ($(v2)!.5!(v3)$);
\end{tikzpicture}
\end{figure}
\end{document}
I would appreciate any tip on the following question.
For a j-period timeline, I like to depict a binary tree up to (including) period 2 (i.e. j = 0,1,2) and then dotted arrows to the final period.
\begin{figure} [H]
\tikzstyle{bag} = [text width=5em, text centered]
\tikzstyle{end} = []
\begin{tikzpicture}[sloped]
\node (a) at ( 0,0) [bag] {$\$ S_{0,0}$}; %[bag] {$ \$ A $}
\node (b) at ( 4,-2) [bag] {$S_{1,0}=S_0 d$}; %[bag] {B}
\node (c) at ( 4,2) [bag] {$S_{1,1}=S_0 u$}; %[bag] {C}
\node (d) at ( 8,-4) [bag] {$S_{2,0}=S_0 d^2$}; %[bag] {D}
\node (e) at ( 8,0) [bag] {$S_{2,1}=S_0 d u$}; %[bag] {E}
\node (f) at ( 8,4) [bag] {$S_{2,2}=S_0 u^2$}; %[bag] {F}
\draw [->] (a) to node [below] {$(1-p)$} (b);
\draw [->] (a) to node [above] {$p$} (c);
\draw [->] (c) to node [below] {$p^2$} (f);
\draw [->] (c) to node [above] {$(1-p)p$} (e);
\draw [->] (b) to node [below] {$(1-p)p$} (e);
\draw [->] (b) to node [above] {$(1-p)^2$} (d);
%Next, the timeline
%use a syntax similar to:
% \draw (0,0) node[below=110pt] {$ n=0 $} node[above=110pt] {$ bla... $};
%for timelines above and below the tree.
%In this case, only the timeline below the tree is used:
\draw (0,0) node[below=140pt] {$ j=0 $} node[above=140pt] {$ i=0 $};
\draw (4,0) node[below=140pt] {$ j=1 $} node[above=140pt] {$ i=0,1 $};
\draw (8,0) node[below=140pt] {$ j=2 $} node[above=140pt] {$ i=0,1,2 $} ;
\draw (10,0) node[below=140pt] {$ \cdots $} node[above=140pt] {$ \cdots $};
\draw (12,0) node[below=140pt] {$ j=T $} node[above=140pt] {$ i=0,1,\cdots,k $};
\end{tikzpicture}
\caption{A binomial tree %
\label{fig:multiperiodtree}}
\end{figure}
There are 2 problems with the output: 1) The formula label at node (2,2) and (2,1) are split into 2 lines, yet node (2,0) is retained on the same line. Why?
2) How to depict dotted arrows to the state where j=T (timeline axis at the bottom of the figure)?
I want to connect the blocks B and M in my code without having the connection line "cutting" F. How can I force the connection to enlarge the connecting line and avoid F?
\documentclass[11pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,shapes.geometric,arrows,positioning,intersections}
\begin{document}
\begin{tikzpicture}[auto,node distance=1cm,thick,
main node/.style={black,draw,minimum width=1.5cm,minimum height=0.75cm}]%circle,draw,font=\sffamily\Large\bfseries}]
\node[main node] (L) {L};
\node[main node] (F) [left = of L ] {F};
\node[main node] (C) [below = of F ] {M};
\node[main node] (B) [right = of L ] {B};
\node[main node] (AP) [below = of B ] {AP};
\node[main node] (A) [below = of L ] {A};
\node[main node] (H) [right = of B ] {H};
\node[main node] (G) [right = of H] {G};
\node[main node] (BR) [below = of G] {BR};
\node[main node] (LR) [below = of BR] {LR};
\node[main node] (U) [below = of AP ] {U};
\node[main node] (P) [below = of U ] {P};
\path[every node/.style={font=\sffamily\small}]
(L) edge node [right] {} (B)
(L) edge node [right] {} (F)
(L) edge node [right] {} (C)
(F) edge node [right] {} (C)
(B.north) edge [out=90,in=90] node [right] {} (F.north)
(B.north) edge [out=90,in=180] node [right] {} (C.west)
(B) edge node [right] {} (AP)
(B) edge node [right] {} (A)
(AP.east) edge [out=0,in=270] node [left] {} (H.south)
(B) edge node [right] {} (H)
(H) edge node [right] {} (G)
(U.east) edge [out=0,in=270] node [left] {} (H.south)
(P.east) edge [out=0,in=270] node [left] {} (H.south)
(U) edge node [right] {} (P)
(BR.west) edge [out=180,in=270] node [right] {} (H.south)
(LR.west) edge [out=180,in=270] node [right] {} (H.south)
(BR.east) edge [out=0,in=0] node [right] {} (G.east)
(LR.east) edge [out=0,in=0] node [right] {} (G.east);
\end{tikzpicture}
\end{document}
This is what I'm getting now
and this is what I'd like to get
Thanks!
There is no direct way to do that in tikz, but this can be achieved by adding intermediate nodes.
Here are two ways to do that.
First one (in blue) uses edges in your main path. As edges only have a single branch, a coordinate is created at a proper position and reused in another edge.
Second way (in red) uses a regular tikz line with several intermediate nodes. It is more flexible and any number of intermediate nodes if required.
Positions of intermediates nodes should tweaked to achieve the desired effect.
\documentclass[11pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,shapes.geometric,arrows,positioning,intersections}
\begin{document}
\begin{tikzpicture}[auto,node distance=1cm,thick,
main node/.style={black,draw,minimum width=1.5cm,minimum height=0.75cm}]%circle,draw,font=\sffamily\Large\bfseries}]
\node[main node] (L) {L};
\node[main node] (F) [left = of L ] {F};
\node[main node] (C) [below = of F ] {M};
\node[main node] (B) [right = of L ] {B};
\node[main node] (AP) [below = of B ] {AP};
\node[main node] (A) [below = of L ] {A};
\node[main node] (H) [right = of B ] {H};
\node[main node] (G) [right = of H] {G};
\node[main node] (BR) [below = of G] {BR};
\node[main node] (LR) [below = of BR] {LR};
\node[main node] (U) [below = of AP ] {U};
\node[main node] (P) [below = of U ] {P};
\path[every node/.style={font=\sffamily\small}]
(L) edge node [right] {} (B)
(L) edge node [right] {} (F)
(L) edge node [right] {} (C)
(F) edge node [right] {} (C)
(B.north) edge [out=90,in=90] node [right] {} (F.north)
%%%% (B.north) edge [out=90,in=180] node [right] {} (C.west)
%west_of_F is an intermediate node to allow a proper connection of B and C
(B.north) edge [blue,out=90,in=90] coordinate[at end] (west_of_F) ($(F.west)+(-1cm,0)$)
(west_of_F) edge [blue, out=-90,in=180] (C.west)
(B) edge node [right] {} (AP)
(B) edge node [right] {} (A)
(AP.east) edge [out=0,in=270] node [left] {} (H.south)
(B) edge node [right] {} (H)
(H) edge node [right] {} (G)
(U.east) edge [out=0,in=270] node [left] {} (H.south)
(P.east) edge [out=0,in=270] node [left] {} (H.south)
(U) edge node [right] {} (P)
(BR.west) edge [out=180,in=270] node [right] {} (H.south)
(LR.west) edge [out=180,in=270] node [right] {} (H.south)
(BR.east) edge [out=0,in=0] node [right] {} (G.east)
(LR.east) edge [out=0,in=0] node [right] {} (G.east);
\draw[red] (B.north) to[out=90,in=0] ($(B.north)+(-3cm,2cm)$)
to [out=180,in=90] ($(C.west)+(-1.1cm,2cm)$)
to [out=-90,in=180] (C.west);
\end{tikzpicture}
\end{document}
I have made a social graph, as you can see below, but couldn't figure out a way to make the nodes inside two circles in which the nodes in the middle (F, D, K, M) are placed in the intersection of the two circles.
And is there a simple way to label left circle, right circle and the intersection?
Here is the code and thank you so much in advance:
\begin{tikzpicture}
\begin{scope}[every node/.style={circle,thick,draw}]
\node (A) at (0,0) {A};
\node (B) at (0,3) {B};
\node (C) at (2,3) {C};
\node (E) at (1,-1.5) {E};
\node (G) at (1,1.5) {G};
\node (F) at (5,2) {F} ;
\node (D) at (4,1) {D};
\node (K) at (5,0) {K};
\node (M) at (4,-1) {M};
\node (H) at (8.5,0) {H};
\node (I) at (9,2.5) {I};
\node (J) at (8,1.5) {J};
\node (N) at (7.5,-1.5) {N};
\node (L) at (7,3) {L} ;
\node (Q) at (9.5,1) {Q} ;
\end{scope}
\begin{scope}[>={Stealth[black]},
every node/.style={fill=white,circle},
every edge/.style={draw=red,very thick}]
\draw (A) -> (G);
\draw (B) -- (A);
\draw (B) -- (C);
\draw (B) -- (G);
\draw (E) -- (G);
\draw (E) -- (A);
\draw (G) -- (C);
\draw (L) -- (I);
\draw (H) -- (J);
\draw (Q) -- (H);
\draw (I) -- (J);
\draw (N) -- (H);
\draw (Q) -- (J);
\draw (A) -> (D);
\draw (E) -- (M);
\draw (E) -- (D);
\draw (G) -- (D);
\draw (G) -- (F);
\draw (C) -- (F);
\draw (C) -- (M);
\draw (N) -- (K);
\draw (N) -- (F);
\draw (N) -- (M);
\draw (L) -- (F);
\draw (J) -- (F);
\draw (H) -- (F);
\end{scope}
\end{tikzpicture}
UPDATE:
After I added these 2 lines:
\draw (2,0.7) circle (4cm);
\draw (7,0.7) circle (4cm);
I get this:
I am only left with coloring the intersection so below these 2 lines I added:
%\draw clip circle (4cm);
%\fill[gray] (2,0.7) circle (4cm);
Which did the job but one of the circles hides its nodes!!
Any suggestions??
I think this is what you're looking for:
\begin{tikzpicture}
\begin{scope}
\draw (2,0.7) circle (4cm);
\clip (7,0.7) circle (4cm);
\fill[gray] (2,0.7) circle (4cm);
\draw (7,0.7) circle (4cm);
\end{scope}
\node[below=4.5cm of circle1] {Circle 1};
\node[below=4.5cm of circle2] {Circle 2};
\node[below=4cm of circle1,xshift=2.5cm] {Intersection};
\begin{scope}[every node/.style={circle,thick,draw}]
\node (A) at (0,0) {A};
\node (B) at (0,3) {B};
\node (C) at (2,3) {C};
\node (E) at (1,-1.5) {E};
\node (G) at (1,1.5) {G};
\node (F) at (5,2) {F} ;
\node (D) at (4,1) {D};
\node (K) at (5,0) {K};
\node (M) at (4,-1) {M};
\node (H) at (8.5,0) {H};
\node (I) at (9,2.5) {I};
\node (J) at (8,1.5) {J};
\node (N) at (7.5,-1.5) {N};
\node (L) at (7,3) {L} ;
\node (Q) at (9.5,1) {Q} ;
\end{scope}
\begin{scope}[>={Stealth[black]},
every node/.style={fill=white,circle},
every edge/.style={draw=red,very thick}]
\draw (A) -> (G);
\draw (B) -- (A);
\draw (B) -- (C);
\draw (B) -- (G);
\draw (E) -- (G);
\draw (E) -- (A);
\draw (G) -- (C);
\draw (L) -- (I);
\draw (H) -- (J);
\draw (Q) -- (H);
\draw (I) -- (J);
\draw (N) -- (H);
\draw (Q) -- (J);
\draw (A) -> (D);
\draw (E) -- (M);
\draw (E) -- (D);
\draw (G) -- (D);
\draw (G) -- (F);
\draw (C) -- (F);
\draw (C) -- (M);
\draw (N) -- (K);
\draw (N) -- (F);
\draw (N) -- (M);
\draw (L) -- (F);
\draw (J) -- (F);
\draw (H) -- (F);
\end{scope}
\end{tikzpicture}
Without seeing how you added the clip and fill instructions, I can't really tell you what's wrong.