6

I have a question similar to TikZ Fading Speed and defining a fading-style directly in the fill command but I can't figure out how to get a nice solution. I would like to, given a list of increasing integers from 0 to 100, generate the following piece of code:

\documentclass[10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{positioning,fit,calc}
\usetikzlibrary{shapes.arrows,chains,decorations.pathreplacing,fadings}
\begin{document}    
\tikzfading[name=fade right0,left color=transparent!0, right color=transparent!70]
\tikzfading[name=fade right1,left color=transparent!70, right color=transparent!100]
\begin{tikzpicture}[start chain=1 going right,node distance=-0.15mm]
    \node [on chain=1] at (-1.5,-.4) {\ldots};
    \node [draw,dashed,on chain=1] {};
    \node [draw,dashed,on chain=1] {};
    \node [draw, dashed, path fading=fade right0, on chain=1] {};
    \node [draw, dashed, path fading=fade right1, on chain=1] {};
\end{tikzpicture}
\end{document}

Here, obviously my list is {0, 70, 100}. I would like to use a foreach loop inide my tikzpicture, but I can't place the \tikzfading inside the tikzpicture, and I didn't suceed in using the answer from the above-mentioned post, could someone help me out ?

Thanks

BigDawg
  • 257

1 Answers1

5

You can do it by the following

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{chains,fadings}
\def\lastx{0}
\foreach \x[remember=\x as \lastx,count=\xi from 0] in {20,40,70,100}{
\tikzfading[name=fade right\xi,left color=transparent!\lastx, right color=transparent!\x]
}
\begin{document}    

\begin{tikzpicture}[start chain=1 going right,node distance=-0.15mm,]
    \node [fill, dashed, path fading=fade right0, on chain=1] {};
    \node [fill, dashed, path fading=fade right1, on chain=1] {};
    \node [fill, dashed, path fading=fade right2, on chain=1] {};
    \node [fill, dashed, path fading=fade right3, on chain=1] {};
\end{tikzpicture}
\end{document}

Well spotted by canaaerus that initially option causes some trouble. There was another question where I had the same problem but I couldn't find it. It's best to define \lastx out of the loop.

enter image description here

percusse
  • 157,807