3

I'm trying to draw a diagram with a bunch of nodes determined using partway calculations. I made a definition using \def\x{.35} to store the partway distance (because I want to use the same distance in a bunch of calculations). (In particular, I want to draw some nodes that are equally spaced on the side of a line, but offset, kind of.)

When I try to use the \x value in a calculation (the commented out line below) where I'm also using a let statement (so that I can do modular arithmetic), it gives me the error Argument of \x has an extra }. Inserted text \par.

If I replace \x with its value .35 in the \path command, everything compiles. The problematic line is commented out in the MWE below.

(I tried enclosing the \x in braces; no good. I tried putting it in the let statement as let \n1 = ..., \n2 = {\x} in ... and that didn't work either.)

What is it about this command instead of the previous ones that TikZ doesn't like?

A minimal-ish working example:

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
\def\z{.1}
\def\x{.35}
\begin{tikzpicture}[vtx/.style={draw, circle, gray, font=\tiny, inner    sep = 1 pt}, flag/.style={draw, circle, font=\tiny, inner sep = 1 pt}, scale = 3]

\node[vtx] (v0) at (0,0){$0$};
\foreach \i in {0, ..., 5}{
\node[vtx] (v1 \i) at (360*\i/6:1){$1_{\i}$};
\path let \n1 = {int(mod(\i+1, 6))} in node[vtx] (v4 \i) at ($(360*\n1/6:1)+(360*\n1/6-30:1)$){$4_{\i}$};
}
\foreach \i in {0, ..., 5}{
\node[flag] (0 \i) at ($(v0)!\x!(v1 \i)!\z!90:(v1 \i)$){};
\node[flag, fill=red] (b \i) at ($(v1 \i)!\x!(v4 \i)!\z!90:(v4 \i)$){};

%\path let  \n1 = {int(mod(\i+1, 6))} in node[flag] (8 \i) at ($(v4 \i)!\x!({v1 \n1})!\z!90:({v1 \n1})$){};
}
\end{tikzpicture}
\end{document}
2

I've changed some calc commands for evaluate options and changed \n1 to \ni in last loop and it worked (no errors, but I don't know if it's the desired result):

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
\def\z{.1}
\def\x{.35}
\begin{tikzpicture}[vtx/.style={draw, circle, gray, font=\tiny, inner    sep = 1 pt}, flag/.style={draw, circle, font=\tiny, inner sep = 1 pt}, scale = 3]

\node[vtx] (v0) at (0,0){$0$};
%\foreach \i in {0, ..., 5}{
%   \node[vtx] (v1 \i) at (360*\i/6:1){$1_{\i}$};
%   \path let \n1 = {int(mod(\i+1, 6))} in node[vtx] (v4 \i) at ($(360*\n1/6:1)+(360*\n1/6-30:1)$){$4_{\i}$};
%}

\foreach \i [evaluate=\i as \angle using 60*\i
            ] in {0, ..., 5}{
    \node[vtx] (v1 \i) at (\angle:1){$1_{\i}$};
    \node[vtx] (v4 \i) at ($(\angle+60:1)+(\angle+30:1)$){$4_{\i}$};
}

\foreach \i [evaluate=\i as \ni using {int(mod(\i+1,6))}] in {0,...,5}{
    \node[flag] (0 \i) at ($(v0)!\x!(v1 \i)!\z!90:(v1 \i)$){};
    \node[flag, fill=red] (b \i) at ($(v1 \i)!\x!(v4 \i)!\z!90:(v4 \i)$){};
    \node[flag] (8 \i) at ($(v4 \i)!\x!(v1 \ni)!\z!90:(v1 \ni)$){};
}

\end{tikzpicture}
\end{document}

enter image description here

  • +1. I do not know if the drawing represents something specific but it's really nice. – Sebastiano Feb 9 '18 at 9:41
  • What does evaluate do? It looks really handy. And what's the difference between \n1 and \ni? I thought you had to go in order like \n1, \n2... – Leah Wrenn Berman Feb 9 '18 at 18:31
  • @LeahWrennBerman Look at section about foreach In pgfmanual. Evaluate does this, computes some operation and stores into a variable. \ni is a variable, \n1 gave me problems. – Ignasi Feb 9 '18 at 21:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.