Take the 2-minute tour ×
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.

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

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

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

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
add comment

Your Answer

 
discard

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.