# How to Draw a Partitioned Circle in TikZ?

I want to draw something like this:

I know everything apart from that circle. This is my code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,shapes.geometric,arrows,fit,calc,positioning,automata,}
\usepackage{amsmath}

\begin{document}

\begin{tikzpicture}[shorten >=1pt,auto,node distance=3 cm, scale = 1.0, transform shape]
\tikzstyle{int}=[draw, minimum size=4em]
\tikzset{every edge/.append style={font=\Large}}
\tikzset{every node/.append style={font=\Large}}

\node[state,minimum size=3 cm]    (A)                                 {};
\node[state,minimum size=3 cm]        (B) [right of=A,node distance=6 cm]                 {};

\node[int]           (C) [above of=A]                     {  };
\node[int]           (D) [below of=A]                     {  };
\node[int]           (E) [above of=B]                     {  };
\node[int]           (F) [below of=B]                     {  };

\path[->] (A) edge [] node []  {} (C);
\path[->] (C) edge [] node []  {} (E);
\path[->] (E) edge [] node []  {} (B);
\path[->] (B) edge [] node []  {} (F);
\path[->] (F) edge [] node []  {} (D);
\path[->] (D) edge [] node []  {} (A);

\end{tikzpicture}

\end{document}


Output is:

-

Here's one possibility using \foreach and its evaluate=<variable> as <macro> using <formula> and count=<macro> from <value> syntax:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,shapes.geometric,arrows,fit,calc,positioning,automata,}
\usepackage{amsmath}

\definecolor{myblue}{RGB}{153,205,255}

\begin{document}

\begin{tikzpicture}[shorten >=1pt,auto,node distance=3 cm, scale = 1.0, transform shape,>=latex]
\tikzset{int/.style={draw, minimum size=4em,fill=myblue}}
\tikzset{every edge/.append style={font=\Large}}
\tikzset{every node/.append style={font=\Large}}

\node[state,minimum size=3 cm,fill=myblue]    (A) {};
\node[state,minimum size=3 cm,fill=myblue]    (B) [right of=A,node distance=6 cm] {};

\node[int]           (C) [above of=A]                     {  };
\node[int]           (D) [below of=A]                     {  };
\node[int]           (E) [above of=B]                     {  };
\node[int]           (F) [below of=B]                     {  };

\path[->] (A) edge [] node []  {} (C);
\path[->] (C) edge [] node []  {} (E);
\path[->] (E) edge [] node []  {} (B);
\path[->] (B) edge [] node []  {} (F);
\path[->] (F) edge [] node []  {} (D);
\path[->] (D) edge [] node []  {} (A);

\draw[<-] (A.180) -- +(-0.5,0);
\draw[->] (B.0) -- +(0.5,0);

\foreach \angle [evaluate=\angle as \langle using 180+\angle] in {0,45,90,135}
{
\draw (A.\angle) -- (A.\langle);
\draw (B.\angle) -- (B.\langle);
}
\foreach \angle [evaluate=\angle as \labangle using \angle+67.5,count=\anglei from 0] in {0,-45,...,-315}
\node at ( $(A) + (\labangle:1cm)$ ) {\anglei};
\end{tikzpicture}

\end{document}


To get labels on the circles, one can always use a \foreach loop over two explicit variables: the first one controlling the angle for the labels and the other one, the label itself; of course, if there's some relationship between the angle and the label, one can use the evaluate=<variable> as <macro> using <formula> syntax to simplify things; the following example illustrates this:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,positioning,automata}

\definecolor{myblue}{RGB}{153,205,255}

\begin{document}

\begin{tikzpicture}

\node[state,minimum size=3 cm,fill=myblue]  (A) {};
\node[state,minimum size=3 cm,fill=myblue]  (B) [right of=A,node distance= 6cm] {};

\foreach \angle [evaluate=\angle as \langle using 180+\angle] in {0,45,90,135}
{
\draw (A.\angle) -- (A.\langle);
\draw (B.\angle) -- (B.\langle);
}

\foreach \angle/\label in {67.5/-5,22.5/4,-22.5/6,-67.5/-1,-112.5/7,-157.5/-8,-202.5/-2,-247.5/0}
\node at ( $(A) + (\angle:1cm)$ ) {\label};
\foreach \angle [evaluate=\angle as \langle using (292.5+\angle)/30] in {67.5,22.5,...,-247.5}
\node at ( $(B) + (\angle:1cm)$ ) {\langle};
\end{tikzpicture}

\end{document}


-
Thanks a lot :). But I didn't understand the code to get numbers in the circle. What should I do to get numbers in second circle? –  tikzlearner Oct 18 '12 at 7:37
@user1280282 I've added an explanation to my updated answer. –  Gonzalo Medina Oct 19 '12 at 0:26
You've already got a thorough answer, but I do wonder if there's another way through something that exists in the shapes library. There is a divided circle with a horizontal line through the centre \node[circle split] {Circle \nodepart{lower} split}; and another with a slash from top left to lower right through the centre \node[forbidden sign,text width=4em, text centered] {Forbidden sign}; as well as a cross over text \node[cross out] {Cross out}; so maybe there are variations on this that can be combined into something useful. –  Jason Whyte Oct 19 '12 at 9:31
@JasonWhyte I don't think something like this already exists in the library, but certainly it seems a good idea to have some kind of circle split shape similar to rectangle split. –  Gonzalo Medina Oct 21 '12 at 19:46
@GonzaloMedina the shapes I described are definitely there in the shapes library, I'm about to post sample code and output. –  Jason Whyte Oct 25 '12 at 6:38
show 1 more comment

The shapes referred to in my comment can be obtained from the following simple code:

\documentclass[a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{shapes,positioning}
\begin{document}
\begin{tikzpicture}[node distance=1cm,blue]
\centering

\node[circle split,draw,] (s1) {Circle \nodepart{lower} split};
\node[forbidden sign,text width=4em, text centered,below=of s1,draw] (s2) {Forbidden sign};

\node[cross out,below=of s2,draw] (s3)  {Cross out};

\end{tikzpicture}

\end{document}


with the result:

-