我将标签放在照片上。有些标签是弯曲的,以跟随图像中的特征。我从 tikzset 调用标签,因为我多次使用同一张照片。
下面的例子有效,但是我想将默认或定义的参数传递给装饰。
例如,在下面的 (MWE) 示例中,我希望标签为黑色和红色。我还希望能够传递文本大小和样式(例如斜体)。
如何将参数传递给装饰器中的文本选项
% tikzpic.tex
\documentclass[tikz, border=20pt]{standalone}% 'crop' is the default for v1.0, before it was 'preview'
\usetikzlibrary{decorations.text}
\tikzset{my labels/.style={},
decorate with/.style= {color = red},
my labels/.pic={
code={\tikzset{scale=1}
\draw [decorate,
domain=-75:-150,
decoration={text along path, text align=center,
text={|\large| My labels},
text align=fit to path}] plot ({1+4.1*sin(\x)}, {1+4.1*cos(\x)});
}}
}
\begin{document}
\begin{tikzpicture}[]
% This should be default black
\path (0,0) pic {my labels};
%This should be red, and smaller (wich it is!)
\path (1,0) pic[scale=0.5, color=blue] {my labels};
\end{tikzpicture}
\end{document}\textsl{}
在下面的例子中,我希望左边的文本为红色(作为默认值),右边的文本为蓝色,如调用时所定义的那样。
答案1
像这样吗?
编辑:我回答了有关将文本传递给装饰的问题,并尝试添加一种插入颜色和粗体的方法,但不知道它是否正确回答了这个问题。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.text}
\tikzset{my labels/.style={},
decorate with/.style= {color = red},
pics/my labels/.style args={#1/#2/#3}{
code={\tikzset{scale=1}
\draw [decorate,
domain=-75:-150,
decoration={text along path, text align=center,
text={|\large\color{blue}| #1},
text align=fit to path}] plot ({1+4.1*sin(\x)}, {1+4.1*cos(\x)});
\draw [decorate,
domain=-20:140,
decoration={text along path,
text={|\large\bf\color{red}| #2},
text align=center,
text align=fit to path}] plot ({2.6*sin(\x)}, {2.6*cos(\x)});
\draw [decorate,
domain=-110:-170,
decoration={text along path,
text={|\tiny\bf\color{olive}| #3},
text align=center,
text align=fit to path}] plot ({3.6*sin(\x)-2.4}, {6.5+4 .6*cos(\x)});
}}
}
\begin{document}
\begin{tikzpicture}[]
\path (0,0) pic[scale=1,color=black] {my labels={first one/second one/third one}};
\path (2,2) pic[scale=1,color=red] {my labels={ARG ONE/ARG TWO/ARG THREE}};
\end{tikzpicture}
\end{document}