我想画一些类似的东西。如何获取矩形边缘标签?
这是 MWE。
\documentclass{article}
\usepackage{tikz}
\usepackage[margin=15mm]{geometry}
\usepackage{calc}
\usetikzlibrary{matrix,arrows}
\usetikzlibrary{positioning,arrows}
\usetikzlibrary{shapes,arrows,fit,calc,positioning,automata}
\begin{document}
\begin{tikzpicture}[>=stealth',shorten >=1pt,auto,node distance=5 cm,thick]
\node[initial,state] (A) [] {};
\node[state] (B) [right of=A] {};
\path[->] (A) edge [] node [] {} (B);
\end{tikzpicture}
\end{document}
如何获取标签?
答案1
一种方法是将其添加到\path
:
\path[->] (A) edge [] node [draw=black, text width=3.0cm, midway, yshift=2ex] {Label} (B);
代码:
\documentclass{article}
\usepackage{tikz}
\usepackage[margin=15mm]{geometry}
\usepackage{calc}
\usetikzlibrary{matrix,arrows}
\usetikzlibrary{positioning,arrows}
\usetikzlibrary{shapes,arrows,fit,calc,positioning,automata}
\begin{document}
\begin{tikzpicture}[>=stealth',shorten >=1pt,auto,node distance=5 cm,thick]
\node[initial,state] (A) [] {};
\node[state] (B) [right of=A] {};
\path[->] (A) edge [] node [draw=black, text width=3.0cm, midway, yshift=2ex] {Label} (B);
\end{tikzpicture}
\end{document}