TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a question about access the mathematical value of count in \foreach, I will used that value to do some calculation in the following code. But it didn't work.

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,calc}
\begin{document}

\begin{tikzpicture}[line cap=round,line join=round,>=triangle    45,x=1.0cm,y=1.0cm]
\clip(-2.5,-3) rectangle (2.5,2.5);
% defining coordinates
\coordinate (origin) at (0,0);
\coordinate (1)      at (0,2);
\coordinate (2)      at ($(origin)!1!120:(1)$);
\coordinate (3)      at ($(origin)!1!120:(2)$);
\coordinate (1_)     at ($(origin)!0.8!-5:(1)$);
\coordinate (2_)     at ($(origin)!0.8!-5:(2)$);
\coordinate (3_)     at ($(origin)!0.8!-5:(3)$);
\coordinate (_1)     at ($(origin)!0.8!5:(1)$);
\coordinate (_2)     at ($(origin)!0.8!5:(2)$);
\coordinate (_3)     at ($(origin)!0.8!5:(3)$);
% draw the circle
\draw [color=black, line width=0.5pt](origin) circle (2 cm);
%draw symmetry elements
\foreach \coordname in {1,2,3}
     \draw [line width=0.5pt, color=black] (\coordname)--     ($(origin)!1!180:(\coordname)$);
\foreach \coordname [count=\i] in {1,2,3}{
     \draw[color=black,font=\large] (\coordname)   node  {\rotatebox{120}{rota}};}
 \draw[color=black,font=\large] (origin)   node {rota};
 % draw plane group notaton
 \draw[color=black] (0,-2.5) node {$222$};
 \end{tikzpicture}
 \end{document}

I need the text rota follow the direction of the curve of the circle depending on the position of the text.

Then I add some code:

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,calc}
\begin{document}

\begin{tikzpicture}[line cap=round,line join=round,>=triangle    45,x=1.0cm,y=1.0cm]
\clip(-2.5,-3) rectangle (2.5,2.5);
% defining coordinates
\coordinate (origin) at (0,0);
\coordinate (1)      at (0,2);
\coordinate (2)      at ($(origin)!1!120:(1)$);
\coordinate (3)      at ($(origin)!1!120:(2)$);
\coordinate (1_)     at ($(origin)!0.8!-5:(1)$);
\coordinate (2_)     at ($(origin)!0.8!-5:(2)$);
\coordinate (3_)     at ($(origin)!0.8!-5:(3)$);
\coordinate (_1)     at ($(origin)!0.8!5:(1)$);
\coordinate (_2)     at ($(origin)!0.8!5:(2)$);
\coordinate (_3)     at ($(origin)!0.8!5:(3)$);
% draw the circle
\draw [color=black, line width=0.5pt](origin) circle (2 cm);
%draw symmetry elements
\foreach \coordname in {1,2,3}
     \draw [line width=0.5pt, color=black] (\coordname)--     ($(origin)!1!180:(\coordname)$);
\foreach \coordname [count=\i] in {1,2,3}{
     \pgfmathsetmacro{\n}{\numbers[\i]};  % add
     \draw[color=black,font=\large] (\coordname)   node  {\rotatebox{-120+30*\n}{rota}};}    %some modification
 \draw[color=black,font=\large] (origin)   node {rota};
 % draw plane group notaton
 \draw[color=black] (0,-2.5) node {$222$};
 \end{tikzpicture}
 \end{document}

It did not work. Anyone has any ideas about what's wrong here? Thanks

share|improve this question
    
Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – JP-Ellis Feb 11 at 7:51
    
Thanks for your reminder – Dan Jiadong Feb 11 at 7:53
    
Thanks :) If it was just \documentclass and \usepackage{tikz}, it wouldn't be too much of an issue, but you're using additional TikZ libraries and you also have \numbers which is undefined. – JP-Ellis Feb 11 at 8:01
    
where is numbers defined? – Ignasi Feb 11 at 8:22
    
\number referred from other answers, I thought it is defined within the tikz package. Maybe this is the problem. – Dan Jiadong Feb 11 at 8:27
up vote 6 down vote accepted

So, in your example, you have \numbers[\i] and I'm not entirely sure what it is referring to. I removed parts of the code that weren't working and tried to see what you were looking for and here is what I have come up with:

\documentclass[tikz,convert]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}    
  \coordinate (origin) at (0,0);

  % draw the circle
  \draw [color=black, line width=0.5pt] (origin) circle (2 cm);

  % draw symmetry elements
  \foreach \coordname [count=\i] in {1,2,...,6} {
    \draw [rotate around={60*\i:(origin)}]
          (origin) -- +(2, 0)
          node [rotate=60*\i, pos=1, right] {rota};
    \coordinate (c\coordname) at ($(origin) + (60*\i:2)$);
  }

  \draw (c1) -- (c2) -- (c3) -- (c4) -- (c5) -- (c6) -- cycle;
\end{tikzpicture}
\end{document}

and the output:

output

I hope that is a helpful starting point for you. Feel free to comment if you have any question as to how parts of this works.

share|improve this answer
    
X and y in tikz pictures is 1cm by default, so I guess you can get rid of that :D – Alenanno Feb 11 at 8:30
    
There's no need for calc and arrows.meta in this code. Also x=1cm, y=1cm are default values. – Ignasi Feb 11 at 8:30
    
Oops, I used these libraries in the first iteration of this answer. I left x and y just in case because he had it in originally. EDIT: Actually, I've changed the code slightly so that it is all relative to (origin). So now I need the calc library again. – JP-Ellis Feb 11 at 8:32
    
Thanks, man, it works for me. I will upload my results. – Dan Jiadong Feb 11 at 8:48

I upload my solution to this question.

\documentclass[margin=10pt]{standalone} \DeclareFontFamily{U}{cry}{\hyphenchar\font=-1} \DeclareFontShape{U}{cry}{m}{n}{ <-> cryst}{} \newcommand{\cry}[1]{{\usefont{U}{cry}{m}{n} \symbol{#1}}} \usepackage{tikz} \usetikzlibrary{arrows,calc} \begin{document} \begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm] \clip(-2.5,-3) rectangle (2.5,2.5); % defining coordinates \coordinate (origin) at (0,0); \coordinate (1) at (0,2); \coordinate (2) at ($(origin)!1!120:(1)$); \coordinate (3) at ($(origin)!1!120:(2)$); % draw the circle \draw [color=black, line width=0.5pt](origin) circle (2 cm); %draw symmetry elements \foreach \coordname in {1,2,3} \draw [line width=0.5pt, color=black] (\coordname)-- ($(origin)!1!180:(\coordname)$); \foreach \coordname [count=\i] in {1,2,3}{ \draw[color=black,font=\large] (\coordname) node [rotate=-210+120*\i] {\cry{2}}; \draw[color=black,font=\large] ($(origin)!-1!(\coordname)$) node [rotate=-210+120*\i] {\cry{2}}; } \draw[color=black,font=\large] (origin) node {\cry{3}}; % draw plane group notaton \draw[color=black] (0,-2.5) node {$32$}; \end{tikzpicture} \end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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