I am trying to create figures of this kind enter image description here

Moreover, I would prefer to create a command with 9 arguments that specify whether each circle is colored in respective color or left white.

As an initial approximation, I thought of using the TIKZ graphs library for this purpose.

I copied this example from the manual:

\setbinding{0cm} % space for binding
\setlrmarginsandblock{*}{3cm}{1} % spine = edge. Edge=3cm
\setulmarginsandblock{3cm}{*}{1} % upper=lower. Upper=3cm
  \graph [nodes={draw, circle}, clockwise, radius=.75cm, empty nodes, n=8] {
    subgraph C_n [name=inner] <->[shorten <=1pt, shorten >=1pt]
    subgraph C_n [name=outer]

I compiled this file with xelatex and this is what I got enter image description here

I was expecting something like this

enter image description here

Any help is appreciated!


I am not sure if I would use graph drawing for this. You seem to know very well how the result should look like, i.e. I do not see the need for a layout algorithm. A very simpleminded macro of the type you suggest is the following. (Fixed colors, modulos can be tricky. ;-)

\node[regular polygon,regular polygon sides=4,draw,minimum size=3cm,\pgfmathresult](square1){};
\node[regular polygon,regular polygon sides=4,draw,minimum size=3cm,rotate=45,\pgfmathresult]
\foreach \X [count=\Y,evaluate=\Y as \Z using {int(mod(\Y+1,2))},
evaluate=\Y as \V using {int((\Y+1)/2)}] in {#1}
  \filldraw[\mycolor] (0,0) circle (3mm);
  \draw[thick,fill=white,draw=\mycolor] (0,0) circle (3mm);
  \filldraw[\mycolor] (square\Z.corner \V) circle (3mm);
  \draw[thick,fill=white,draw=\mycolor] (square\Z.corner \V) circle (3mm);

enter image description here

The 0 and 1 entries determine if a given circle is filled, the 9th entry is the dot in the middle. The colors are stored in the \mycolors array.

| improve this answer | |
  • 1
    This is an incredible answer: fast and precise! – yarchik Sep 11 '18 at 13:23

Here is a simple way to draw.

\fill[cyan] (0,0) circle(\r);

\draw[gray] (-\a,-\a) rectangle (\a,\a);
\filldraw (\a,-\a) circle(\r);
\filldraw (-\a,\a) circle(\r);
\filldraw (-\a,-\a) circle(\r);
\filldraw (\a,\a) circle(\r);

\draw[red] (-\a,-\a) rectangle (\a,\a);
\filldraw[red] (\a,-\a) circle(\r);
\filldraw[red] (\a,\a) circle(\r);
\filldraw[red] (-\a,-\a) circle(\r);
\draw[red,fill=white] (-\a,\a) circle(\r);

enter image description here

| improve this answer | |

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.