我怎样才能装饰路径的每个给定边而不是整个路径?

我怎样才能装饰路径的每个给定边而不是整个路径?

如果我在 TikZ 中有一条路径,我可以轻松地根据其整体范围对其进行装饰。但是,我也可以只在其边缘添加装饰吗?

在我的例子中

\documentclass[tikz]{standalone}

\usetikzlibrary{decorations.markings}

\begin{document}
\begin{tikzpicture}[decoration={
    markings,% switch on markings
    mark=% actually add a mark
    between positions 0 and 1 step 10mm
    with
    {
        \draw (0pt,-2pt) -- (0pt,2pt);
    }
}]
\draw [help lines] grid (3,2);
\draw [postaction={decorate}] (0,0) -- (3,1) -- (2,2) -- (2,1) -- cycle;
\end{tikzpicture}
\end{document}

我只想要在(0,0)(3,1)(2,2)处有垂直线(2,1)

答案1

show path construction我自己解决了这个问题,实际上您可以使用该技术作为后续操作在每个段的末尾获得垂直标记:

\documentclass[tikz]{standalone}

\usetikzlibrary{arrows.meta,decorations.pathreplacing}

\tikzset{
    show segments/.style={
        decoration={
            show path construction,
            moveto code={},
            lineto code={
                \draw [{Tee Barb[line width=1pt,inset=0pt,length=0pt,width=12]}-{Tee Barb[line width=1pt,inset=0pt,length=0pt,width=12]}] (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
            },
            curveto code={
                \draw [{Tee Barb[line width=1pt,inset=0pt,length=0pt,width=12]}-{Tee Barb[line width=1pt,inset=0pt,length=0pt,width=12]}] (\tikzinputsegmentfirst) .. controls
                (\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb)
                ..(\tikzinputsegmentlast);
            },
            closepath code={
                \draw [{Tee Barb[line width=1pt,inset=0pt,length=0pt,width=12]}-{Tee Barb[line width=1pt,inset=0pt,length=0pt,width=12]}] (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
            }
        },decorate
    }
}

\begin{document}
\begin{tikzpicture}
\draw [help lines] grid (3,2);
\draw [postaction=show segments] (0,0) -- (3,1) -- (2,2) -- (2,1) -- cycle;
\end{tikzpicture}
\end{document}

其结果是:

在此处输入图片描述

相关内容