我想画一条从圆的一部分延伸出来的线。当我使用>=latex
箭头时,这两条线会产生偏移。选项也是如此shorten
。其中一个就足以创建偏移。
当我从样式定义中删除>=latex
它时它就消失了。shorten...
是否可以使用没有偏移的latex
箭头和选项?shorten
编辑:我在坐标 处添加了一个红色圆圈mid1
。为什么不在从到mid1
绘制的路径上?coord1
coord2
以下是 MWE:
\documentclass[border=1pt, tikz]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[connA/.style = {thin, ->, >=latex, shorten <=2pt, shorten >=2pt, bend left=45}]
\coordinate (startcoord);
\coordinate[below=3cm of startcoord] (coord1);
\coordinate[left=3cm of startcoord] (coord2);
\draw[connA] (coord1) to coordinate[midway] (mid1) (coord2);
\draw[connA] (mid1) .. controls +(135:1cm) and +(0:1cm) .. (-4,-1);
\fill[red] (mid1) circle (0.5pt);
\end{tikzpicture}
\end{document}
我使用 TeX Live 2020。
答案1
缩短通过弯曲路径定义的曲线总是会产生这种错误,这也是我所苦苦挣扎的痛苦。最近,我做了此代码这很容易适应您当前的问题,您已经提到了这个线程。
这需要一点理解,但没什么大不了的。您可以使用贝塞尔曲线(使用.. controls
)定义路径,然后计算此曲线上的一系列点(从起点到一定长度),然后使用您想要的任何装饰在这些点之间绘制一条折线。
\documentclass[border=1pt, tikz]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\coordinate (startcoord);
\coordinate[below=3cm of startcoord] (coord1);
\coordinate[left=3cm of startcoord] (coord2);
% Defining the first path with Bezier curve
\def\route1{(coord1) .. controls +(-2,0) and +(0,-2).. (coord2)}
% Definig the midpoint of this first path
\path \route1 coordinate[midway] (mid1);
% Defining starting point and length of the reduced arrow
\def\start{0.01}
\def\len{0.98}
\def\numpoints{200} % number of points to draw a broken line following the curve
%---------------------------------
% First path from coord1 to coord2
%---------------------------------
\path \route1
{\foreach \i in {1,...,\numpoints} { coordinate[pos=\start+\len*\i/\numpoints] (p\i) } };
% Drawing a broken line linking all 200 points, with the arrow decoration at the end
\draw[-latex,thin] (p1)
{ \foreach \j in {2,...,\numpoints} {-- (p\j) } };
%--------------------------
% Second path from midpoint
%--------------------------
\def\route2{(mid1) .. controls +(135:1cm) and +(0:1cm) .. (-4,-1)}
\def\start{0} \def\len{0.95} \def\numpoints{50}
\path \route2
{\foreach \i in {1,...,\numpoints} { coordinate[pos=\start+\len*\i/\numpoints] (p\i) } };
\draw[-latex,thin] (p1)
{ \foreach \j in {2,...,\numpoints} {-- (p\j) } };
% Decoration just in case
\fill[red] (mid1) circle (0.5pt);
\fill[blue] (startcoord) circle (.5pt);
\fill[blue] (coord1) circle (.5pt);
\fill[blue] (coord2) circle (.5pt);
\end{tikzpicture}
\end{document}
答案2
目前,我使用手动方式修正这个难看的偏移:
\documentclass[border=1pt, tikz]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[connA/.style = {thin, ->, >=latex, shorten <=2pt, shorten >=2pt, bend left=45}]
\coordinate (startcoord);
\coordinate[below=3cm of startcoord] (coord1);
\coordinate[left=3cm of startcoord] (coord2);
\draw[connA] (coord1) to coordinate[midway] (mid1) (coord2);
% identify the correct angle for various positions of mid1 manually
\draw[blue, thick] (mid1) to ([shift=(225:1mm)] mid1);
\fill[red] (mid1) circle (0.5pt);
% tune shift length manually
\draw[connA] ([shift=(255:0.275mm)] mid1) .. controls +(135:1cm) and +(0:1cm) .. (-4,-1);
\end{tikzpicture}
\end{document}