TikZ decorations.pathreplacing 和 lineto curve 被忽略

TikZ decorations.pathreplacing 和 lineto curve 被忽略

为什么装饰选项被忽略了?

在此处输入图片描述

\documentclass[tikz,margin=3pt]{standalone}
\usetikzlibrary{decorations.pathreplacing}

\tikzset{alamain/.style={%
    decoration={%
    lineto code={
        \draw[red] (\tikzinputsegmentfirst) 
            to [out=10 , in=190]
            (\tikzinputsegmentlast) ;
        }
    },
    }
}

\begin{document}

\begin{tikzpicture}
\draw [help lines] grid (3,2);

\draw [alamain] (0,0) -- (3,1) ;
\draw [blue] (0,0) to [out=10 , in=190] (3,1) ;

\end{tikzpicture}

\end{document}

答案1

您缺少装饰名称show path construction和使装饰激活的操作decorate。最后,第二条路径过度绘制,因此不可见,您需要稍微移动它才能看到

\documentclass[tikz]{standalone}
\usetikzlibrary{decorations.pathreplacing}

\tikzset{alamain/.style={%
    decoration={show path construction,%
    lineto code={
        \draw[red] (\tikzinputsegmentfirst) 
            to [out=10 , in=190]
            (\tikzinputsegmentlast) ;
        }
    },decorate
    }
}

\begin{document}

\begin{tikzpicture}
\draw [help lines] grid (3,2);

\draw [alamain] (0,0) -- (3,1) ;
\draw [blue] (0,0) to [out=20 , in=200] (3,1) ;

\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容