3

I'm trying to make a series of circles with gradients. On the second page, which is created, there is only /2pt/1pt/2pt and on the last /20pt. I guess there's something wrong with my foreach loop, but I don't know what.

\documentclass[tikz]{standalone}
\usepackage{xcolor}

\definecolor{myyellow}{cmyk}{0,0,10,0}

\begin{document}

\foreach \Radius/\j in {6.0/1, 6.05/2,...,8.0/42}
{
    \begin{tikzpicture}[scale=.5]
        \pgfmathsetmacro\k{\j*10}
        \useasboundingbox[fill=black] (-8.2,-8.2) rectangle (8.2cm,8.2cm);
        \fill[fill=myyellow!\k] (0,0) circle (\Radius);
    \end{tikzpicture}
}

\end{document}

Error:

Illegal unit of measure (pt inserted).

<to be read again> 
                   /
l.15 }
  • Crosspost in German: texwelt.de/wissen/fragen/24430/… – Henri Menke Mar 17 at 20:27
  • @HenriMenke The cross post seems to be deleted (after I added an answer, as you suggested me to do).... – marmot Mar 17 at 21:33
  • The error is explained in this answer: foreach don't recognise a pattern in a list like {6/1, 7/2, ... , 10/5}. The ... is only usable with one variable. If you use a construction like \foreach \x / \y in , avoid using ... in the list. – quark67 Mar 17 at 22:45
  • @marmot I'm sorry, I deleted the question before I saw that it was answered, because I already got the answer here. – Simba Mar 18 at 6:37
2

You need to use integers for the color fraction, and there is the option of using count for this very situation.

\documentclass[tikz]{standalone}
\usepackage{xcolor}

\definecolor{myyellow}{cmyk}{0,0,10,0}

\begin{document}

\foreach \Radius [count=\j] in {6.0, 6.05,...,8.0}
{
    \begin{tikzpicture}[scale=.5]
        \pgfmathtruncatemacro\k{\j*10}
        \useasboundingbox[fill=black] (-8.2,-8.2) rectangle (8.2cm,8.2cm);
        \fill[fill=myyellow!\k] (0,0) circle (\Radius);
    \end{tikzpicture}
}

\end{document}

enter image description here

3

It doesn't really make sense to do myyellow!420: all values from 100 on will produce the same color.

Here the gradient goes from 2 to 84 with step 2.

\documentclass[tikz]{standalone}
\usepackage{xcolor}

\definecolor{myyellow}{cmyk}{0,0,10,0}

\begin{document}

\foreach \x in {2,4,...,84}
  {
    \begin{tikzpicture}[scale=.5]
        \pgfmathsetmacro\Radius{(\x-2)/41+6}
        \useasboundingbox[fill=black] (-8.2,-8.2) rectangle (8.2cm,8.2cm);
        \fill[fill=myyellow!\x] (0,0) circle (\Radius);
    \end{tikzpicture}
  }

\end{document}

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.