当我使用以下代码时,绘图之间会出现分号。我该如何解决这个问题?
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
{
\newcommand\partFillRec[1]{%
\begin{tikzpicture}
\coordinate (a) at (0,0);
\coordinate (b) at (1,1);
\draw[very thick, draw=red, fill=yellow!40] (a) rectangle (b);
\draw[draw=none, fill=red] (a) rectangle ($(a-|b)!#1!(b)$);
\end{tikzpicture}%
}
\foreach \x in {0,.2,...,1} \partFillRec{\x};
}
\end{document}
答案1
将代码参数放入,\foreach
而{…}
不是用分号终止它:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand\partFillRec[1]{%
\begin{tikzpicture}
\coordinate (a) at (0,0);
\coordinate (b) at (1,1);
\draw[very thick, draw=red, fill=yellow!40] (a) rectangle (b);
\draw[draw=none, fill=red] (a) rectangle ($(a-|b)!#1!(b)$);
\end{tikzpicture}%
}
\begin{document}
\foreach \x in {0,.2,...,1} {\partFillRec{\x}}
\end{document}