在 tikz 中我有以下三个节点:
\documentclass{article}
\usepackage{pgf, tikz}
\usetikzlibrary{arrows, automata}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[>= stealth, shorten >= 1pt,node distance = 3cm,semithick%, auto]
\tikzstyle{every state}=[draw = black,thick,fill = white]
\node[state] (p11) {$p_{1,1}$};
\node[state] (p12) [right of=p11] {$p_{1,2}$};
\coordinate (Middle) at ($(p11)!0.5!(p12)$);
\node[state] (t1) [below of=Middle] {$t_1$};
\end{tikzpicture}
\end{document}
我想在节点的中心添加标签,然后让标签指向每个节点。如下所示:
我该怎么做?顺便说一句,我没有auto
启用属性,tikzpicture
因为它会弄乱边缘内的中间标签。
任何帮助都非常感谢。谢谢!
编辑:完整代码已更新
答案1
这是一个简单的修改:
\documentclass[tikz,multi,border=10pt]{standalone}
\usetikzlibrary{arrows.meta,automata,calc}
\begin{document}
\begin{tikzpicture}
[% \tikzstyle is deprecated - use \tikzset{} instead
>= Stealth,
shorten >= 1pt,
node distance = 3cm,
semithick,
every state/.style={draw = black, thick, fill = white},
]
\node[state] (p11) {$p_{1,1}$};
\node[state] (p12) [right of=p11] {$p_{1,2}$};
\coordinate (Middle) at ($(p11)!0.5!(p12)$);
\node[state] (t1) [below of=Middle] {$t_1$};
\node (here) at ($(t1)!1/2!(Middle)$) {My label};
\path [->] (here) edge (p11) edge (p12) edge (t1);
\end{tikzpicture}
\end{document}
得出
我已部分更新了语法以使用arrows.meta
和避免\tikzstyle
。但是,理想情况下,您也会使用该positioning
库及其语法。