问题是用开关画一条弯曲的线

问题是用开关画一条弯曲的线

这个问题与这个问题。我想在两点之间画一个箭头,箭头中间有一个开关。我按照上面链接的建议做了,但这种方法并不通用,每次我们都必须在那里玩数字才能得到我们想要的。例如,考虑以下代码:

\documentclass[12pt]{report}
\usepackage{tikz} 
\usepackage{circuitikz} 
\usepackage{tikz-cd} 
\usetikzlibrary{arrows,decorations.markings,decorations} 
\usetikzlibrary{arrows,shapes,calc,positioning} 
\tikzstyle{block} = [draw,rectangle, rounded corners, minimum width=1cm, minimum height=0.8cm,text centered, line width=2pt ]
\tikzstyle{arrow} = [thick,->,>=stealth,line width=2pt]
\tikzset{addarrow/.style={decoration={markings, mark=at position 1 with {\arrow{stealth}}}, postaction={decorate}} } 
\begin{document} 
\begin{figure} 
\begin{tikzpicture} 
\node (b) at (1,1)  {$A$};
\node (a) at (2.5,-1.9)  {$B$};
\draw  [->,>=stealth,line width=1pt] (a)  to[out=105,in=-50] coordinate[pos=.35] (A) coordinate[pos=.55] (B) (b) ; 
\fill[white] ( [yshift=-2mm] A) rectangle ( [yshift=1mm] B); 
\draw [line width=1pt] (A) to[cspst] (B); 
\end{tikzpicture} 
\end{figure} 
\end{document}

输出如下。在此处输入图片描述 可以看出,开关没有完全连接到线路。我们该如何解决这个问题?为什么代码中有 0.35 和 -2mm(坐标 [pos=.35],[yshift=-2mm])?

答案1

有几种方法可以改善开关和线条之间的连接。一种是在连接点处添加点。另一种是将填充圆的半径减小约线宽的一半。

\documentclass[12pt]{report}
\usepackage{tikz} 
\usepackage{circuitikz} 
\usepackage{tikz-cd} 
\usetikzlibrary{arrows,decorations.markings,decorations} 
\usetikzlibrary{arrows,shapes,calc,positioning} 
\tikzstyle{block} = [draw,rectangle, rounded corners, minimum width=1cm, minimum height=0.8cm,text centered, line width=2pt ]
\tikzstyle{arrow} = [thick,->,>=stealth,line width=2pt]
\tikzset{addarrow/.style={decoration={markings, mark=at position 1 with {\arrow{stealth}}}, postaction={decorate}} } 
\begin{document} 
\begin{figure} 
\begin{tikzpicture} 
\node (b) at (1,1)  {$A$};
\node (a) at (2.5,-1.9)  {$B$};
\draw  [->,>=stealth,line width=1pt] (a)  to[out=105,in=-50] coordinate[pos=.35] (A) coordinate[pos=.55] (B) (b) ; 
\fill[white] let \p1=($(A)-(B)$), \n2={.5*veclen(\x1,\y1)-.25pt}
   in ($(A)!.5!(B)$) circle(\n2);
\draw [line width=.5pt] (A) to[cspst,*-*] (B);
\end{tikzpicture} 
\end{figure} 
\end{document}

演示

相关内容