在這貼文詳細解釋如何用箭頭裝飾輪廓。我怎麼才能做同樣的事情,但使一個輪廓有一個方向的箭頭,而另一個輪廓有相反的箭頭?輪廓處於相同的tikzpicture
環境。也許可以定義裝飾的多個實例嗎?
答案1
您可以定義多個標記,並且可以透過沿相反方向繪製路徑或使用反向箭頭定義標記來反轉。
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\tikzset
{marking1/.style=
{decoration=
{markings,
mark=at position 0.5 with {\arrow[line width=1pt]{>}}
},
postaction=decorate
},
marking1reversed/.style=
{decoration=
{markings,
mark=at position 0.5 with {\arrow[line width=1pt]{<}}
},
postaction=decorate
},
marking2/.style=
{decoration=
{markings,
mark=at position 0.33 with {\arrow[line width=1pt]{stealth}},
mark=at position 0.66 with {\arrow[line width=1pt,xscale=-1]{stealth}}
},
postaction=decorate
}
}
\begin{document}
\begin{tikzpicture}
% a path with three sections
\draw[marking1] (0,0) -- (2,0);
\draw[marking1] (2,0) -- (1,1);
\draw[marking1] (1,1) -- (0,0);
% path drawn in the opposite direction, with the same marking
\begin{scope}[xshift=3cm]
\draw[marking1] (0,0) -- (1,1);
\draw[marking1] (1,1) -- (2,0);
\draw[marking1] (2,0) -- (0,0);
\end{scope}
% the original path, but with another marking that reverses the arrows
\begin{scope}[xshift=6cm]
\draw[marking1reversed] (0,0) -- (2,0);
\draw[marking1reversed] (2,0) -- (1,1);
\draw[marking1reversed] (1,1) -- (0,0);
\end{scope}
% the original path with a completely different marking
\begin{scope}[xshift=9cm]
\draw[marking2] (0,0) -- (2,0);
\draw[marking2] (2,0) -- (1,1);
\draw[marking2] (1,1) -- (0,0);
\end{scope}
\end{tikzpicture}
\end{document}