我有以下独立的类文件来为期刊论文创建图表:
\documentclass[12pt,A4paper]{standalone}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{tkz-graph}
\usepackage{wasysym}
\begin{document}
\centering
\begin{tikzpicture}
\SetUpEdge[lw = 1pt, color = black]
\GraphInit[vstyle=Normal]
\SetGraphUnit{4}
\tikzset{VertexStyle/.append style={fill}}
\Vertex[L=$ x~{+\!\!=}~\delta x $]{Begin}
\EA(Begin){Turn}
\EA[unit=4](Turn){Direction}
\NO[unit=3,L=$ y~{+\!\!=}~\delta y $](Direction){Up}
\SO[unit=3,L=$ y~{-\!\!=}~\delta y $](Direction){Down}
\WE[unit=4,L=$ x {=} 0${,~}$y {=} 0$](Begin){Start}
\tikzset{EdgeStyle/.style={->}}
\Edge[label=$ p_{\mathrm{straight} } $](Start)(Begin)
\Loop[dir=NO, dist=80,label=$ 1- p_{\mathrm{straight}} $](Start)
\Edge[style={bend left=15}, label = $ 1 $](Begin)(Turn)
\Edge[style={bend left=15},label=$ 1-p_{\mathrm{turn}} $](Turn)(Begin)
\Edge[label=$ p_{\mathrm{turn}}$](Turn)(Direction)
\Edge[label=$ p_{\mathrm{up}} $](Direction)(Up)
\Edge[label=$ 1-p_{\mathrm{up}} $](Direction)(Down)
\Edge[style={bend right=20},label=$ 1 $](Up)(Begin)
\Edge[style={bend left=20}, label = $ 1 $](Down)(Begin)
\end{tikzpicture}
生成以下图像:
但是,我想移动左侧被循环切开的标签,使其位于循环正上方。到目前为止,我还无法做到这一点,也找不到我使用的 \Loop 命令的文档。
任何能解决此问题的建议或资源都将不胜感激。
答案1
下面是使用 的图表matrix of math nodes
:
代码:
\documentclass[tikz,border=4mm]{standalone}
\usepackage{amsmath}
\usetikzlibrary{matrix}
\newcommand\pe{\mathop{{+}{=}}}
\newcommand\me{\mathop{{-}{=}}}
\begin{document}
\begin{tikzpicture}[>=stealth,->,
overwrite/.style={midway,fill=white}]
\matrix (M)[matrix of math nodes,row sep=10mm,column sep=20mm,
every node/.append style={circle,draw=black!80!blue, thick, minimum size=12mm}]{
& & & y\pe\delta y\\
\substack{x=0\\ y=0}& x \pe\delta x & \text{Turn} & \text{Direction}\\
& & & y\me\delta y\\
};
\draw(M-2-1) --node[overwrite]{$p_{\text{straight}}$} (M-2-2);
\draw(M-2-1) to [out=145,in=35,min distance=18mm]
node[above]{$1-p_{\text{straight}}$} (M-2-1);
\draw(M-2-2) to [out=20,in=160] node[overwrite]{$1$}(M-2-3);
\draw(M-2-3) to [out=200,in=340]node[overwrite]{$1-p_{\text{turn}}$}(M-2-2);
\draw(M-2-3) --node[overwrite]{$p_{\text{turn}}$} (M-2-4);
\draw(M-2-4) --node[overwrite]{$p_{\text{up}}$} (M-1-4);
\draw(M-2-4) --node[overwrite]{$1-p_{\text{up}}$} (M-3-4);
\draw(M-1-4.west) to [out=180, in=65]node[overwrite]{$1$} (M-2-2);
\draw(M-3-4.west) to [out=180, in=295]node[overwrite]{$1$} (M-2-2);
\end{tikzpicture}
\end{document}
您可以通过更改 轻松调整行和列间距row sep=10mm,column sep=20mm
。我定义了运算符\pe
和,\me
并使节点周围的圆圈变粗,而不是箭头变粗,但除此之外,这大致相同。