I want to create a series of rectangles, each with a different shade. The shade varies from white to black. I want to make the white (first) rectangle visible by drawing its border.
My first step is to draw all the rectangles, without any conditional code:
\documentclass{standalone}
\usepackage[rgb]{xcolor}
\usepackage{tikz}
\usetikzlibrary{chains}
\begin{document}
\begin{tikzpicture}[start chain=chroma going below,
node distance=2mm,
every node/.style={shape=rectangle,minimum size=1cm},
]
\foreach \n [evaluate=\n as \value using 1-\n*0.125] in {0,...,8}
{
\definecolor{tmpc}{Hsb}{0,0,\value}
\draw node[on chain,fill=tmpc] {};
}
\end{tikzpicture}
\end{document}
I tried to replace the foreach
code with this:
{
\definecolor{tmpc}{Hsb}{0,0,\value}
\draw node[on chain,fill=tmpc] {}
\ifnum\n=0
(\tikzlastnode) [late options={draw}] % no effect
(\tikzlastnode.east) [draw] -- ++(1cm,0) % drawn correctly
\fi
; % ends the path
}
Adding draw
to the node options directly works. Only the late options
don't behave like I expect them to do – maybe I'm not understanding something here? I have added code to see if the ifnum
code is actually executed, and it is indeed.
Is there a class of options that don't work as late options
?
Best Answer
A slightly different way is described in the following code. Note that you don't really need
xcolor
for this. Twotikz
pictures are drawn, one usingxcolor
, the other using the basic commands intikz
. I drew the chain horizontally to save on space. I also added a macro that let's you change the number of nodes.The output is