
저는 knots
tikzlibrary를 사용하여 몇 가지 매듭을 그리고 있으며 매듭의 방향을 지정하고 싶었습니다. 즉 화살표를 추가하고 싶었습니다. 나는 원하는 지점에 화살표를 삽입하는 "arrowat"라고 부르는 장식 스타일을 사용합니다(예: \draw[arrowat=0.5]
결과 선을 따라 중간에 화살표가 생성됩니다). 이는 다음과 같이 정의됩니다.
\tikzset{%
arrowat/.style={%
postaction={decorate,decoration={
markings,
mark=at position #1 with {\arrow[xshift=2pt]{>}}}}
}
}
그러나 매듭에 이 스타일을 사용하려고 하면 몇 가지 문제가 발생합니다. 특정 지점에서는 모든 것이 잘 작동하지만 특정 지점에서 화살표를 그리려고 하면 여러 개의 화살표(및 선의 간격)가 나타납니다. 아래는 제대로 작동하는 경우(왼쪽)와 그렇지 않은 경우(오른쪽)를 모두 보여주는 MWE입니다. 내 질문은: 이 문제를 어떻게 해결하거나 발생을 방지하려면 어떻게 해야 합니까?
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings,knots}
\tikzset{%
arrowat/.style={%
postaction={decorate,decoration={
markings,
mark=at position #1 with {\arrow[xshift=2pt]{>}}}}
}
}
\begin{document}
\begin{tikzpicture}
\begin{knot} [consider self intersections, ignore endpoint intersections=false, clip width=7, flip crossing=3]
\strand [thick, arrowat=0.8] (0,0)
to [out=180, in=270] (-1,1)
to [out=90, in=180] (1,2.5)
to [out=0, in=90] (3,1)
to [out=270, in=0] (2,0)
to [out=180, in=270] (-0.2,2.5)
to [out=90, in=180] (1,3.8)
to [out=0, in=90] (2.2,2.5)
to [out=270, in=0] (0,0);
\end{knot}
\end{tikzpicture}
\begin{tikzpicture}
\begin{knot} [consider self intersections, ignore endpoint intersections=false, clip width=7, flip crossing=3]
\strand [thick, arrowat=0.5] (0,0)
to [out=180, in=270] (-1,1)
to [out=90, in=180] (1,2.5)
to [out=0, in=90] (3,1)
to [out=270, in=0] (2,0)
to [out=180, in=270] (-0.2,2.5)
to [out=90, in=180] (1,3.8)
to [out=0, in=90] (2.2,2.5)
to [out=270, in=0] (0,0);
\end{knot}
\end{tikzpicture}
\end{document}
답변1
나는 진정한(즉, 우아한) 해결책을 갖고 있지 않습니다. 무슨 일이 일어나고 있는지 부분적으로 이해하고 Ti가 얼마나 자주 발생하는지 확인하고 싶습니다.케이지생각한다0.5 위치에 있습니다. 이 예에서는 10번입니다. 주석을 제거하여 이를 확인할 수 있습니다 \typeout{\number\value{arrowcount}}
. 그런 다음 화살표가 실제로 그려질 위치를 알려주는 스위치를 추가할 수 있습니다. 해당 스타일을 이라고 합니다 conditional arrow at
.
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings,knots}
\newcounter{arrowcount}
\tikzset{%
arrowat/.style={%
postaction={decorate,decoration={
markings,
mark=at position #1 with {\arrow[xshift=2pt]{>}}}}
},
conditional arrow at/.style 2 args={%
postaction={decorate,decoration={
markings,
mark=at position #1 with {\stepcounter{arrowcount}%
%\typeout{\number\value{arrowcount}}%
\ifnum\value{arrowcount}=#2
\arrow[xshift=2pt]{>}%
\fi}}}
},
}
\begin{document}
\begin{tikzpicture}
\begin{knot} [consider self intersections, ignore endpoint intersections=false, clip width=7, flip crossing=3]
\strand [thick, arrowat=0.8] (0,0)
to [out=180, in=270] (-1,1)
to [out=90, in=180] (1,2.5)
to [out=0, in=90] (3,1)
to [out=270, in=0] (2,0)
to [out=180, in=270] (-0.2,2.5)
to [out=90, in=180] (1,3.8)
to [out=0, in=90] (2.2,2.5)
to [out=270, in=0] (0,0);
\end{knot}
\end{tikzpicture}
\begin{tikzpicture}
\begin{knot} [consider self intersections, ignore endpoint intersections=false, clip width=7, flip crossing=3]
\strand [thick,conditional arrow at={0.5}{6}] (0,0)
to [out=180, in=270] (-1,1)
to [out=90, in=180] (1,2.5)
to [out=0, in=90] (3,1)
to [out=270, in=0] (2,0)
to [out=180, in=270] (-0.2,2.5)
to [out=90, in=180] (1,3.8)
to [out=0, in=90] (2.2,2.5)
to [out=270, in=0] (0,0);
\end{knot}
\end{tikzpicture}
\end{document}
키를 사용할 때 상황은 (예상대로) 2배 정도 개선됩니다 only when rendering
. 그러면 "단지" 5개의 슬롯만 있고 각 슬롯은 실제로 화살표로 연결됩니다.
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings,knots}
\newcounter{arrowcount}
\tikzset{%
arrowat/.style={%
postaction={decorate,decoration={
markings,
mark=at position #1 with {\arrow[xshift=2pt]{>}}}}
},
conditional arrow at/.style 2 args={%
postaction={decorate,decoration={
markings,
mark=at position #1 with {\stepcounter{arrowcount}%
\typeout{\number\value{arrowcount}}%
\ifnum\value{arrowcount}=#2
\arrow[xshift=2pt]{>}%
\fi}}}
},
}
\begin{document}
\begin{tikzpicture}
\begin{knot} [consider self intersections, ignore endpoint intersections=false, clip width=7, flip crossing=3]
\strand [thick, arrowat=0.8] (0,0)
to [out=180, in=270] (-1,1)
to [out=90, in=180] (1,2.5)
to [out=0, in=90] (3,1)
to [out=270, in=0] (2,0)
to [out=180, in=270] (-0.2,2.5)
to [out=90, in=180] (1,3.8)
to [out=0, in=90] (2.2,2.5)
to [out=270, in=0] (0,0);
\end{knot}
\end{tikzpicture}
\begin{tikzpicture}
\begin{knot} [consider self intersections, ignore endpoint intersections=false, clip width=7, flip crossing=3]
\strand [thick,only when rendering/.style={conditional arrow at={0.5}{3}}] (0,0)
to [out=180, in=270] (-1,1)
to [out=90, in=180] (1,2.5)
to [out=0, in=90] (3,1)
to [out=270, in=0] (2,0)
to [out=180, in=270] (-0.2,2.5)
to [out=90, in=180] (1,3.8)
to [out=0, in=90] (2.2,2.5)
to [out=270, in=0] (0,0);
\end{knot}
\end{tikzpicture}
\end{document}
따라서 문제는 경로가 세그먼트로 분해되는 것 같습니다. 이는 화살표를 보이지 않는 경로에 대신 연결할 수 있음을 알려줍니다.
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings,knots}
\newcounter{arrowcount}
\tikzset{%
arrowat/.style={%
postaction={decorate,decoration={
markings,
mark=at position #1 with {\arrow[xshift=2pt,opacity=1]{>}}}}
},
}
\begin{document}
\begin{tikzpicture}
\begin{knot} [consider self intersections, ignore endpoint intersections=false, clip width=7, flip crossing=3]
\strand [thick, arrowat=0.8] (0,0)
to [out=180, in=270] (-1,1)
to [out=90, in=180] (1,2.5)
to [out=0, in=90] (3,1)
to [out=270, in=0] (2,0)
to [out=180, in=270] (-0.2,2.5)
to [out=90, in=180] (1,3.8)
to [out=0, in=90] (2.2,2.5)
to [out=270, in=0] (0,0);
\end{knot}
\end{tikzpicture}
\begin{tikzpicture}
\begin{knot} [consider self intersections, ignore endpoint intersections=false, clip width=7, flip crossing=3]
\def\mypath{(0,0) to [out=180, in=270] (-1,1)
to [out=90, in=180] (1,2.5)
to [out=0, in=90] (3,1)
to [out=270, in=0] (2,0)
to [out=180, in=270] (-0.2,2.5)
to [out=90, in=180] (1,3.8)
to [out=0, in=90] (2.2,2.5)
to [out=270, in=0] (0,0)}
\draw[thick,opacity=0,arrowat=0.55] \mypath;
\strand [thick] \mypath;
\end{knot}
\end{tikzpicture}
\end{document}
이는 이러한 제안 중 가장 우아한 제안일 수 있으며 0.5의 "진짜" 화살표가 교차점에 의해 가려져 있음을 보여줍니다.