!["잘못된 측정 단위(pt 삽입)" foreach 문제](https://rvso.com/image/392319/%22%EC%9E%98%EB%AA%BB%EB%90%9C%20%EC%B8%A1%EC%A0%95%20%EB%8B%A8%EC%9C%84(pt%20%EC%82%BD%EC%9E%85)%22%20foreach%20%EB%AC%B8%EC%A0%9C.png)
그라데이션을 사용하여 일련의 원을 만들려고 합니다. 생성된 두 번째 페이지에는 /2pt/1pt/2pt만 있고 마지막 /20pt에는 있습니다. 내 foreach 루프에 문제가 있는 것 같지만 무엇인지 모르겠습니다.
\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}
오류:
Illegal unit of measure (pt inserted).
<to be read again>
/
l.15 }
답변1
색상 분수에 대해 정수를 사용해야 하며 count
바로 이 상황에 사용할 수 있는 옵션이 있습니다.
\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}
답변2
이렇게 하는 것은 실제로 의미가 없습니다 myyellow!420
. 100부터 모든 값은 동일한 색상을 생성합니다.
여기서 그라디언트는 2단계에서 2에서 84까지입니다.
\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}