TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

\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] {};

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 ?


share|improve this question
up vote 5 down vote accepted

You can do it by the following

\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{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] {};

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

share|improve this answer
It seems like \lastx is always 0!?! – canaaerus Aug 3 '12 at 10:31
@canaaerus You are right, it happened to me before with initially option. I'll fix it in a sec. – percusse Aug 3 '12 at 10:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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