0

I am putting labels on top of photos. Some labels are curved, to follow features in the image. I am calling the labels from a tikzset, as I am using the same photo multiple times.

The example below works, however, I would like to pass default or defined arguments to the decorations.

E.g, in the (MWE) example below, I would like the labels to be black and red. I would also like to be able to pass text size and style (e.g. italics).

How can I pass arguments to text options in a decorator

% 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{}

In the example below, I would like the left text to be red (as default value), and the right to be blue, as defined when called.

enter image description here

1 Answer 1

1

Something like this?
EDIT: I aswered the question about passing text to decoration and tried to add a way to insert colours and bold, but don't know if it answers properly the question.

arguments passed to decoration

\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}
1
  • Thanks! My question was rather about how to set a default value for decorators' options in the tikzset. I will try to clarify the question.
    – user2821
    Jul 23, 2021 at 6:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .