圆头箭头和 [blank=soft] 选项存在问题(来自业余 TikZ 库)

圆头箭头和 [blank=soft] 选项存在问题(来自业余 TikZ 库)

我刚刚发现Round Cap箭头,我想用它来改进我之前的回答

但是如果路径坐标中有一个[blank=soft]选项(来自 TikZlibrary ) ,它就无法满足我的需要。hobby

查看以下 MWE 中用红色圈出的箭头尾部。

确实,第二张图中的圆形尾巴就是缝隙后面的尾巴!

\documentclass{article}
\usepackage{calc}
\usepackage{tikz}
\usetikzlibrary{hobby, arrows.meta,bending}

\newcommand*{\jdx}[1][1]{%
\begin{tikzpicture}[baseline, xscale=#1]
\draw[black, {Round Cap}-{To[angle=90:.3cm 1,length=9mm, flex'=.86]}, line width=4pt] (.1,.85) to [curve through={(.79,.18) .. (1.45,.7) .. (1.2,1.6) .. (.9,1.6) .. (1.9,1.6)}]
(2.1,2.5);
\node[red, circle, draw, text width=10pt] at (.1,.85) {};
\end{tikzpicture}}

\newcommand*{\gapdx}[1][1]{%
\begin{tikzpicture}[baseline, xscale=#1]
\draw[black, {Round Cap}-{To[angle=90:.3cm 1,length=9mm, flex'=.86]}, line width=4pt] (.1,.85) to [curve through={(.79,.18) .. (1.45,.7) 
(1.48,.8) .. 
([blank=soft]1.43,1.4)
.. (1.2,1.6) .. (.9,1.6) .. (1.9,1.6)}]
(2.1,2.5);
\node[red, circle, draw, text width=10pt] at (.1,.85) {};
\node[blue, circle, draw, text width=10pt] at (1.43,1.4) {};
\end{tikzpicture}}


\begin{document}
Without \verb|[blank=soft]| is OK:

\jdx

With \verb|[blank=soft]| the rounded end is not where I need it, here I want a rounded end where there is the red circle and a sharp end where there is the blue one:

\gapdx

\end{document}

enter image description here

答案1

这并没有解释问题,也没有试图解决它。但是您可以通过line cap=round在您的路径上使用来解决此限制。

round line cap

\documentclass{article}
\usepackage{calc}
\usepackage{tikz}
\usetikzlibrary{hobby, arrows.meta,bending}

\newcommand*{\jdx}[1][1]{%
\begin{tikzpicture}[baseline, xscale=#1]
\draw[black, {Round Cap}-{To[angle=90:.3cm 1,length=9mm, flex'=.86]}, line width=4pt] (.1,.85) to [curve through={(.79,.18) .. (1.45,.7) .. (1.2,1.6) .. (.9,1.6) .. (1.9,1.6)}]
(2.1,2.5);
\node[red, circle, draw, text width=10pt] at (.1,.85) {};
\end{tikzpicture}}

\newcommand*{\gapdx}[1][1]{%
\begin{tikzpicture}[baseline, xscale=#1]
\draw[black,line cap=round, -{To[angle=90:.3cm 1,length=9mm, flex'=.86]}, line width=4pt] (.1,.85) to [curve through={(.79,.18) .. (1.45,.7) 
(1.48,.8) .. 
([blank=soft]1.43,1.4)
.. (1.2,1.6) .. (.9,1.6) .. (1.9,1.6)}]
(2.1,2.5);
\node[red, circle, draw, text width=10pt] at (.1,.85) {};
\end{tikzpicture}}


\begin{document}
Without \verb|[blank=soft]|:

\jdx

With \verb|[blank=soft]|:

\gapdx

\end{document}

编辑:由于您实际上希望除了路径的结束部分之外有清晰的线条,因此这里有另一种解决方法。请注意,这与您最初要求 TikZ 执行的操作不同。

faked line cap

\documentclass{article}
\usepackage{calc}
\usepackage{tikz}
\usetikzlibrary{hobby, arrows.meta,bending}

\newcommand*{\jdx}[1][1]{%
\begin{tikzpicture}[baseline, xscale=#1]
\draw[black, {Round Cap}-{To[angle=90:.3cm 1,length=9mm, flex'=.86]}, line width=4pt] (.1,.85) to [curve through={(.79,.18) .. (1.45,.7) .. (1.2,1.6) .. (.9,1.6) .. (1.9,1.6)}]
(2.1,2.5);
\node[red, circle, draw, text width=10pt] at (.1,.85) {};
\end{tikzpicture}}

\newcommand*{\gapdx}[1][1]{%
\begin{tikzpicture}[baseline, xscale=#1]
\draw[black, -{To[angle=90:.3cm 1,length=9mm, flex'=.86]}, line width=4pt] (.1,.85) to [curve through={(.79,.18) .. (1.45,.7) (1.48,.8) .. ([blank=soft]1.43,1.4) .. (1.2,1.6) .. (.9,1.6) .. (1.9,1.6)}]
(2.1,2.5);
\fill (.1,.85) circle (2pt);
\node[red, circle, draw, text width=10pt] at (.1,.85) {};
\end{tikzpicture}}


\begin{document}
Without \verb|[blank=soft]|:

\jdx

With \verb|[blank=soft]|:

\gapdx

\end{document}

答案2

这主要是为了说明一下你在这里看到的是标准的 TiZ 行为。也就是说,在我看来,hobby它的行为方式应该如此。这个答案还添加了另一种添加圆角帽的方法,这与第二种方法非常相似TeXnician 的精彩回答(但不需要您明确输入圆的坐标)。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{hobby, arrows.meta,bending,decorations.markings}

\newcommand*{\jdx}[1][1]{%
\begin{tikzpicture}[baseline, xscale=#1]
\draw[black, {Round Cap}-{To[angle=90:.3cm 1,length=9mm, flex'=.86]}, line width=4pt] (.1,.85) to [curve through={(.79,.18) .. (1.45,.7) .. (1.2,1.6) .. (.9,1.6) .. (1.9,1.6)}]
(2.1,2.5);
\node[red, circle, draw, text width=10pt] at (.1,.85) {};
\end{tikzpicture}}

\newcommand*{\gapdx}[1][1]{%
\begin{tikzpicture}[baseline, xscale=#1]
\draw[black, -{To[angle=90:.3cm 1,length=9mm, flex'=.86]}, line width=4pt,
postaction={decorate,
decoration={markings,mark=at position 0 with {\fill (0,0) circle (2pt) ;}}
}] (.1,.85) to [curve through={(.79,.18) .. (1.45,.7) 
(1.48,.8) .. 
([blank=soft]1.43,1.4)
.. (1.2,1.6) .. (.9,1.6) .. (1.9,1.6)}]
(2.1,2.5);
\node[red, circle, draw, text width=10pt] at (.1,.85) {};
\node[blue, circle, draw, text width=10pt] at (1.43,1.4) {};
\end{tikzpicture}}


\newcommand*{\standardz}[1][1]{%
\begin{tikzpicture}[baseline, xscale=#1]
\draw[black, {Round Cap}-{To[angle=90:.3cm 1,length=9mm, flex'=.86]}, 
line width=4pt] 
(.1,.85) to[bend right] 
(1.48,.8) 
(1.43,1.4) to[bend right] (2.1,2.5);
\node[red, circle, draw, text width=10pt] at (.1,.85) {};
\node[blue, circle, draw, text width=10pt] at (1.43,1.4) {};
\end{tikzpicture}}


\begin{document}
Without \verb|[blank=soft]| on has one path, and the arrow heads are in the
beginning and at the end of the path:

\jdx

Standard Ti\emph{k}Z behavior: whenever there is a gap in the path, the arrow
heads are attached at the last stretch.

\standardz


The Hobby paths do not behave differently. If you want to add a round line cap
at the beginning, you may just use decorations, which affect the whole path.

\gapdx

\end{document}

enter image description here

相关内容