有没有办法可以重复使用路径来进行绘图和文本装饰?
我想避免重复(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 path
和use path
键。未来版本的 Ti 中,我们试图让这些键更加通用钾Z,请继续关注。
答案2
您可以使用preaction
或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,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}