2

In this MWE, it is expected to get seven circles equally spaced in the angular direction with stretching radius. However, I got this weird output.

\documentclass[border=2pt]{standalone}
\usepackage{tikz}

\begin{document}
    \begin{tikzpicture}
     \foreach[count=\i] \x in {0,1,...,6}{%
        \pgfmathtruncatemacro\ml{1.2^(\i-1)}
        \draw (1,1)++(\x*30:5*\ml) circle[radius=1];
    }
\end{tikzpicture}
\end{document}

enter image description here

1 Answer 1

6

The problem is that you are using \pgfmathtruncatemacro which discards everything after the decimal point. The first four powers of 1.2 lie between 1 and 2 so truncate to 1. The next three lie between 2 and 3 so truncate to 2. To fix this, replace \pgfmathtruncatemacro with \pgfmathsetmacro.

\documentclass[border=2pt]{standalone}
%\url{http://tex.stackexchange.com/q/362136/86}
\usepackage{tikz}

\begin{document}
    \begin{tikzpicture}
     \foreach[count=\i] \x in {0,1,...,6}{%
  \pgfmathsetmacro\ml{1.2^(\i-1)}
  %\pgfmathtruncatemacro\ml{1.2^(\i-1)}
        \draw (1,1) ++(\x*30:5*\ml) circle[radius=1];
    }
\end{tikzpicture}
\end{document}

(I added lines to the circles in the picture to show the radii more explicitly.)

Expanding radii

3
  • Many thanks, I followed this answer, but it seems I didn't pay enough attention to this matter.
    – Diaa
    Apr 4, 2017 at 19:12
  • 1
    @DiaaAbidou In that answer the use of \pgfmathtruncatemacro is to ensure that what goes at the end of the \foreach loop is definitely an integer (and not even, say, 2.0). This is a common habit that some of us have gotten into because it avoids an occasional issue with the \foreach loop. Apr 4, 2017 at 19:16
  • I see, I appreciate your willingness to explain it to me. Many Thanks.
    – Diaa
    Apr 4, 2017 at 19:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .