两次使用路径(绘制然后装饰)

两次使用路径(绘制然后装饰)

有没有办法可以重复使用路径来进行绘图和文本装饰?

我想避免重复(6.8cm,-1.7) -- (9.5cm,-1.7) arc (-90:0:1.5) -- (11cm,1.5)以下内容。

\documentclass[border=1mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows, decorations.text}
\tikzset{>=latex}
\begin{document}
\begin{tikzpicture}
\draw[->, cyan!50!white, line width=1.5mm ] (6.8cm,-1.7) -- (9.5cm,-1.7) arc (-90:0:1.5) -- (11cm,1.5);
\draw[decoration={text along path, text={|\sffamily|gather},text align={center},raise=0.2cm},decorate] (6.8cm,-1.7) -- (9.5cm,-1.7) arc (-90:0:1.5) -- (11cm,1.5);
\end{tikzpicture}
\end{document}

答案1

这就是postaction目的。您只需将第二个\draw[...]命令的参数放入postaction={...},然后将其添加到第一个路径。

\documentclass[border=1mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows, decorations.text}
\tikzset{>=latex}
\begin{document}
\begin{tikzpicture}
\draw[->, cyan!50!white, line width=1.5mm,postaction={decoration={text along path, text={|\sffamily|gather},text align={center},raise=0.2cm},decorate}] (6.8cm,-1.7) -- (9.5cm,-1.7) arc (-90:0:1.5) -- (11cm,1.5);
\end{tikzpicture}
\end{document}

在此处输入图片描述

可以postaction经常任意使用。

\documentclass[border=1mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows, decorations.text}
\tikzset{>=latex}
\begin{document}
\begin{tikzpicture}
\draw[->, cyan!50!white, line width=1.5mm,
postaction={decoration={text along path, text={|\sffamily|gather},text
align={center},raise=0.2cm},decorate},
postaction={decoration={text along path, text={|\sffamily|hibernate},text
align={center},raise=-0.3cm},decorate},
] (6.8cm,-1.7) -- (9.5cm,-1.7) arc (-90:0:1.5) -- (11cm,1.5);
% sadly, text decorations do not get taken into account automatically
% when determining the bounding box
\path (current bounding box.south) ++ (0,-3mm) 
(current bounding box.east) ++ (3mm,0); 
\end{tikzpicture}
\end{document}

在此处输入图片描述

回收路径的另一种方法是使用save pathuse path键。未来版本的 Ti 中,我们试图让这些键更加通用Z,请继续关注。

答案2

您可以使用preactionpostaction

\documentclass[border=1mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows, decorations.text}
\tikzset{>=latex}
\begin{document}
\begin{tikzpicture}
\draw[->, cyan!50!white, line width=1.5mm,preaction={decoration={text along path, text={|\sffamily|gather},text align={center},raise=0.2cm},decorate} ] (6.8cm,-1.7) -- (9.5cm,-1.7) arc (-90:0:1.5) -- (11cm,1.5);

%\draw[] (6.8cm,-1.7) -- (9.5cm,-1.7) arc (-90:0:1.5) -- (11cm,1.5);
\end{tikzpicture}
\end{document}

截屏

相关内容