I'd like to use tikz to draw regular polygons that are too small for shapes.geometric. My goal is to have them in-line with the text:
But when I try to write a tikzset to so I can quickly and easily draw any given polygon, I get an error ! Illegal unit of measure (pt inserted).
I think the issue is that I perform calculations on the argument of the tikzset inside the set that defines a for loop. But I don't know how get TeX to recognize the argument as numeric.
Here's my working code for the text above:
\documentclass[border=0.2cm]{standalone} \usepackage{tikz} \begin{document} \newdimen\R \R=0.1cm foo \begin{tikzpicture} % Indicate the boundary of the regular polygons \draw[xshift=2.5\R] (0:\R) \foreach \x in {90,180,...,359} { -- (\x:\R) } -- cycle (90:\R) ; \end{tikzpicture} baz \begin{tikzpicture} % Indicate the boundary of the regular polygons \draw[xshift=2.5\R] (0:\R) \foreach \x in {72,144,...,360} { -- (\x:\R) } -- cycle (90:\R) ; \end{tikzpicture} \end{document} (I got the code for the polygons here.)
And the broken code:
\documentclass[border=0.2cm]{standalone} \usepackage{tikz} \tikzset{ pics/Polygon/.style n args ={2}{% background code = { \draw[xshift=2.5*#2] (0:#2) \foreach \x in {360/#1,2*360/#1,...,360} { -- (\x:#2) } -- cycle (360/3:#2); } } } \begin{document} \begin{tikzpicture} \draw (0,0) pic {Polygon={5}{0.8cm}}; \end{tikzpicture} \end{document} From playing around with different options, I know the problem is that 360/#1 and 2*360/#1 don't work well in set used to define the for loop.






cycle? That's just a move-to to that point.