如果我尝试在 $Z_2$ 上的循环中添加松散标志,则以下代码无法编译。如何更改循环的松散程度?请注意,删除松散标志后,代码可以编译。
\documentclass[]{beamer}
\usetheme{Madrid}
\usepackage{amsfonts}
\usepackage{amsmath,amssymb,bm}
\usepackage{mathtools}
\usepackage{multirow}
\usepackage{float}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\usepackage{xcolor}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{tikz}
\usetikzlibrary{automata,arrows.meta, positioning}
\tikzset{
->, % makes the edges directed
>=stealth, % makes the arrow heads bold
node distance=3cm, % specifies the minimum distance between two nodes. Change if necessary.
every state/.style={thick, fill=gray!10}, % sets the properties for each ’state’ node
initial text=$ $, % sets the text that appears on the start arrow
}
\begin{document}
\begin{frame}
\begin{tikzpicture}
\node[] (z1) at (0,0) { };
\node[right = 3cm of z1] (z2) {};
\draw (z1) edge node[midway,above] {$a$} (z2);
\draw (z2) edge[loop right,looseness=33] node[above,outer sep=4pt,pos=0.2] {$a$} ();
\end{tikzpicture}
\end{frame}
\end{document}
我收到的错误信息是:
! Package pgf Error: No shape named `' is known.
See the pgf package documentation for explanation.
Type H <return> for immediate help.
...
l.39 \end{frame}
答案1
指定将使用 的内部样式looseness = 33
覆盖该集合。to path
loop
loop right
如果我们改变loop
它似乎可以正常工作。
或者,只需再次指定起始坐标作为目标。
如果您希望所有循环都具有这种松散性,请调整every loop
样式:
every loop/.append style={looseness=33}
通常,用于循环的节点较大且大多为圆形,此时默认松散度和/或最小距离似乎恰到好处。
代码
\documentclass[tikz]{standalone}
\usetikzlibrary{arrows.meta, positioning}
\tikzset{
loop/.code={% overwrite default, what will it break?
\let\tikztotarget\tikztostart,
\pgfkeysalso{looseness=8,min distance=+5mm,every loop}}}
\begin{document}
\begin{tikzpicture}[>=Stealth, node distance=3cm]
\node[draw] (z1) {};
\node[draw, right = 3cm of z1] (z2) {};
\path (z1) edge node[midway,above] {$a$} (z2)
(z2) edge[loop right, looseness=33]
node[above, outer sep=4pt, pos=0.2] {$a$} ()
% edge[help lines, loop right] () % compare with default
;
\end{tikzpicture}
\end{document}