„Unzulässige Maßeinheit (pt eingefügt)“ Problem mit foreach

„Unzulässige Maßeinheit (pt eingefügt)“ Problem mit foreach

Ich versuche, eine Reihe von Kreisen mit Farbverläufen zu erstellen. Auf der zweiten Seite, die erstellt wird, steht nur /2pt/1pt/2pt und auf der letzten /20pt. Ich vermute, dass mit meiner Foreach-Schleife etwas nicht stimmt, aber ich weiß nicht, was.

\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}

Fehler:

Illegal unit of measure (pt inserted).

<to be read again> 
                   /
l.15 }

Antwort1

Sie müssen für den Farbanteil ganze Zahlen verwenden und es besteht die Möglichkeit, countfür genau diese Situation zu verwenden.

\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}

Bildbeschreibung hier eingeben

Antwort2

Das macht eigentlich keinen Sinn myyellow!420: Alle Werte ab 100 ergeben die gleiche Farbe.

Hier geht die Steigung von 2 bis 84 mit Stufe 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}

verwandte Informationen