Comportamento inesperado de decorações de setas em nós: aparecem múltiplas setas e lacunas

Comportamento inesperado de decorações de setas em nós: aparecem múltiplas setas e lacunas

Estou usando a knotstikzlibrary para desenhar alguns nós e queria orientar meus nós, ou seja, adicionar uma seta. Eu uso um estilo de decoração que chamei de "arrowat", que insere uma flecha no local desejado (por exemplo, \draw[arrowat=0.5]produzirá uma flecha no meio da linha resultante). É definido da seguinte forma

\tikzset{% 
    arrowat/.style={%
        postaction={decorate,decoration={
                markings,
                mark=at position #1 with {\arrow[xshift=2pt]{>}}}}
    }
}

No entanto, surgem alguns problemas quando tento usar este estilo em um nó: em certos pontos, as coisas funcionam bem, mas se tento desenhar uma seta em outros pontos, aparecem múltiplas setas (e lacunas na linha). Abaixo está um MWE, mostrando um caso em que as coisas funcionam bem (esquerda) e outro em que não funcionam (direita). Minha pergunta é: como faço para corrigir isso, ou melhor, evitar que isso aconteça?

insira a descrição da imagem aqui

\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}

Responder1

Não tenho uma solução verdadeira (ou seja, elegante). Apenas curioso para entender parcialmente o que está acontecendo e verificar com que frequência o TikZachaestá na posição 0,5. Neste exemplo isso é 10 vezes, você pode verificar isso descomentando \typeout{\number\value{arrowcount}}. Então pode-se adicionar uma chave que diz em qual deles a seta deve realmente ser desenhada. O estilo correspondente é chamado 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}

insira a descrição da imagem aqui

A situação melhora por um fator 2 (conforme esperado) ao usar a only when renderingchave. Então você tem “apenas” 5 slots, e cada um deles realmente leva a uma flecha.

\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}

Parece que o problema é que o caminho é decomposto em segmentos. Isso nos diz que podemos anexar a seta a um caminho invisível.

\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}

insira a descrição da imagem aqui

Esta pode ser a mais elegante destas propostas e também revela que a seta “verdadeira” em 0,5 está obscurecida por um cruzamento.

informação relacionada