I have this diagram, and I have tried to draw it doing every dot and line, but I was wondering, is there a way to do it with foreach cycles or something like that? thanks.

enter image description here

  • 4
    What have you tried so far? Anyway you are not a new user anymore
    – user156344
    Apr 20 '19 at 8:37
  • 2
    @close-voters: The OP hasn't been online for 2 hours, i.e. he doesn't know what is going on yet. Give him some time.
    – user156344
    Apr 20 '19 at 10:44
  • @JouleV Questions can also be reopened. In its current state it is unclear. Therefore voting to close. Apr 20 '19 at 11:38
  • @HenriMenke The question is not unclear. OP informs us that he/she have solved the problem, but the code used is not optimal OP then asks if somebody may give him a tip how to solve the same with a loop or similar. OP does not ask you to write the code, just provide a hint, as JouleV has done.
    – Sveinung
    Apr 20 '19 at 13:00

This does not provide a full code, but a hint so that you can shorten your code. You can use a pic for every group of dots like that.

  dotcirc/.style={circle,inner sep=2pt,draw,fill=#1},
  pics/tripdots/.style args={#1/#2-#3/#4-#5/#6,name=#7}{
      \begin{scope}[local bounding box=#7]
        \draw (-1.2,0)--(1.2,0);
        \draw (0,0.2)--(0,-.2);
        \path (-1,0) node[dotcirc=#1] (#2) {};
        \path (0,0)  node[dotcirc=#3] (#4) {};
        \path (1,0)  node[dotcirc=#5] (#6) {};
\pic at (0,0) {tripdots={red/ra-yellow/ya-green/ga,name=a}};
\draw[<-] (a) -- ++(.5,1) node[above] {\scalebox{0.5}{Traffic lights}};
\draw[<-] (ra) -- ++ (.5,-1) node[below] {\scalebox{0.5}{A colored circle}};

enter image description here

  • A good answer to the question. :)
    – Sveinung
    Apr 20 '19 at 13:01
  • Thanks a lot!. And a question, I have hear somethimes that "pic" use, but I don't know how it is, is that a package? I know I am not new at this but there are a lot of things I still don't know about tex.
    – TeemoJg
    Apr 20 '19 at 17:23
  • 1
    @J.Rodriguez You just have to read chapter 18 of the PGF manual. pic is very useful - it is a syntax in TikZ, not a package.
    – user156344
    Apr 20 '19 at 17:26

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.