4

I try to generate several copies of a faded text using the PG 3.0 pic feature but something with the placement went wrong. Only the one at the origin is drawn.

Here is what I have done:

\documentclass[varwidth,margin=5mm]{standalone} 
\usepackage{tikz}
\usetikzlibrary{fadings}

\tikzset{
   myPic/.pic={
  \begin{tikzfadingfrompicture}[name = fading letter]
    \node[text = transparent!0, inner xsep = 0pt, outer xsep = 0pt] {test text};
  \end{tikzfadingfrompicture}
    \node[inner sep = 0pt, outer sep = 0pt] (textnode) {\phantom{test text}}; 
    \shade[path fading = fading letter, left color = blue, right color = green, fit fading = false, opacity=0.5] (textnode.south west) rectangle (textnode.north east);% 
   }
}

\begin{document} 
\begin{tikzpicture}
  \pic at (0,0)    {myPic};

  \pic at (0,2)    {myPic};
\end{tikzpicture}
\end{document}

Any help to solve it is highly welcome.

5

You need to also shift the fading with fading transform. I added

fading transform={shift={(textnode)}}

to get

\documentclass[varwidth,margin=5mm]{standalone} 
\usepackage{tikz}
\usetikzlibrary{fadings}

\tikzset{
   myPic/.pic={
  \begin{tikzfadingfrompicture}[name = fading letter]
    \node[text = transparent!0, inner xsep = 0pt, outer xsep = 0pt] {test text};
  \end{tikzfadingfrompicture}
    \node[inner sep = 0pt, outer sep = 0pt] (textnode) {\phantom{test text}}; 
    \shade[path fading = fading letter, left color = blue,
     right color = green, fit fading = false, opacity=0.5,
     fading transform={shift={(textnode)}}] (textnode.south west) rectangle (textnode.north east);% 
   }
}

\begin{document} 
\begin{tikzpicture}
  \pic at (0,0)    {myPic};

  \pic at (0,2)    {myPic};
\end{tikzpicture}
\end{document}

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.