我希望如果标签与我的任何边缘相交,则标签位于边缘上方。我也在使用 Overleaf。我尝试将标签填充为白色,但它不会删除所有交叉点。
\documentclass{article}
\usepackage{amsmath}
\usepackage{graphicx} % Required for inserting images
\usepackage{tikz}
\usepackage{amsthm}
\usetikzlibrary {calc,positioning,shapes.misc}
\usetikzlibrary{matrix}
\usepackage[a4paper, total={6in, 8in}]{geometry}
\usetikzlibrary{calc}
\usetikzlibrary {arrows.meta}
\usetikzlibrary {shapes.geometric}
\usepackage{algorithm}
\usepackage{mathrsfs}
\usepackage{algpseudocode}
\usepackage{stmaryrd}
\usetikzlibrary {automata,positioning}
\title{Angluin Description with Examples and Illustrations}
\author{Coping Forever}
\date{January 2024}
\begin{document}
\begin{tikzpicture}[
node distance=2cm,
every initial by arrow/.style={text=white,->},
line width=1pt,
mylabel/.style={font=\bfseries, inner sep=2pt, rectangle, draw=black,fill=white}
]
\node[state, initial, initial where=right, initial text={}] (s0) at (4.00, 0.00) {$s_0$};
\node[state,accepting] (s1) at (2.00, 3.46) {$s_1$};
\node[state] (s2) at (-2.00, 3.46) {$s_2$};
\node[state] (s3) at (-4.00, 0.00) {$s_3$};
\node[state] (s4) at (-2.00, -3.46) {$s_4$};
\node[state] (s5) at (2.00, -3.46) {$s_5$};
\path[arrows = {-Latex[line width=3pt, length=10pt]}] (s0) edge[bend right] node [mylabel] {0} (s1);
\path[->] (s0) edge[bend right] node [mylabel] {1} (s3);
\path[->] (s1) edge[loop above] node [mylabel] {0} ();
\path[->] (s1) edge[bend right] node [mylabel] {1} (s3);
\path[->] (s2) edge[bend right] node [mylabel] {0} (s5);
\path[->] (s2) edge[bend right] node [mylabel] {1} (s1);
\path[->] (s3) edge[bend right] node [mylabel] {0} (s2);
\path[->] (s3) edge[bend right] node [mylabel] {1} (s4);
\path[->] (s4) edge[bend right] node [mylabel] {0} (s3);
\path[->] (s4) edge[bend right] node [mylabel] {1} (s2);
\path[->] (s5) edge[bend right] node [mylabel] {0} (s4);
\path[->] (s5) edge[loop above] node [mylabel] {1} ();
\end{tikzpicture}
\end{document}
在fill=white
我收到这个之后
答案1
\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary {automata, positioning, arrows.meta}
\pgfdeclarelayer{foreground}\pgfdeclarelayer{background}
\pgfsetlayers{background, main, foreground}
\makeatletter\ExplSyntaxOn
\tl_replace_once:Nnn \tikz@fig@continue { \setbox } { \tikz@setbox@which }
\ExplSyntaxOff
\let\tikz@setbox@which\setbox
\tikzset{node on layer/.code={%
\expandafter\def\expandafter\tikz@whichbox\expandafter
{\csname pgf@layerbox@#1\endcsname}%
\def\tikz@setbox@which{\global\setbox}}}
\makeatother
\begin{document}
\begin{tikzpicture}[
thick,
mylabel/.style={font=\bfseries, inner sep=2pt, draw, fill=white, node on layer=foreground},
]
\node[state, initial, initial where=right, initial text={}] (s0) at (4.00, 0.00) {$s_0$};
\node[state, accepting] (s1) at (2.00, 3.46) {$s_1$};
\node[state] (s2) at (-2.00, 3.46) {$s_2$};
\node[state] (s3) at (-4.00, 0.00) {$s_3$};
\node[state] (s4) at (-2.00, -3.46) {$s_4$};
\node[state] (s5) at (2.00, -3.46) {$s_5$};
\path[arrows = {-Latex[line width=3pt, length=10pt]}] (s0) edge[bend right] node [mylabel] {0} (s1);
\path[->] (s0) edge[bend right] node [mylabel] {1} (s3);
\path[->] (s1) edge[loop above] node [mylabel] {0} ();
\path[->] (s1) edge[bend right] node [mylabel] {1} (s3);
\path[->] (s2) edge[bend right] node [mylabel] {0} (s5);
\path[->] (s2) edge[bend right] node [mylabel] {1} (s1);
\path[->] (s3) edge[bend right] node [mylabel] {0} (s2);
\path[->] (s3) edge[bend right] node [mylabel] {1} (s4);
\path[->] (s4) edge[bend right] node [mylabel] {0} (s3);
\path[->] (s4) edge[bend right] node [mylabel] {1} (s2);
\path[->] (s5) edge[bend right] node [mylabel] {0} (s4);
\path[->] (s5) edge[loop above] node [mylabel] {1} ();
\end{tikzpicture}
\end{document}