24

I need to draw a two-colored circle split, exactly as is specified in the section 39.6 of the manual for rectangle splits, meaning that one half of the circle split has one fill color and the other half a different fill color. I have to rotate it afterwards, but that is not a problem.

For rectangle splits is seems to be as easy as adding the option rectangle split part fill={red, blue} in the definition. Is there a similar way to multiple-color circle splits?

Greetings from Chile,
Marcelo.

1
  • no the option circle split part fill does not exist. May 13, 2012 at 4:44

1 Answer 1

33

Final code

Correction of bugs

1) \begin{scope}[on background layer] is not useful.

2) Instead of \insiderad-0.5\pgflinewidth, the correct code is \insiderad-\pgflinewidth

The style circle split part fill needs two colors like in circle split part fill={blue!50,red!50}

Here a complete example

\documentclass[11pt]{scrartcl}
\usepackage{tikz}
\usetikzlibrary{shapes,backgrounds,calc}

\makeatletter
\tikzset{circle split part fill/.style  args={#1,#2}{%
 alias=tmp@name, % Jake's idea !!
  postaction={%
    insert path={
     \pgfextra{% 
     \pgfpointdiff{\pgfpointanchor{\pgf@node@name}{center}}%
                  {\pgfpointanchor{\pgf@node@name}{east}}%            
     \pgfmathsetmacro\insiderad{\pgf@x}
      %\begin{scope}[on background layer]
      %\fill[#1] (\pgf@[email protected]) ([xshift=-\pgflinewidth]\pgf@[email protected]) arc
      %                    (0:180:\insiderad-0.5\pgflinewidth)--cycle;
      %\fill[#2] (\pgf@[email protected]) ([xshift=\pgflinewidth]\pgf@[email protected])  arc
      %                     (180:360:\insiderad-0.5\pgflinewidth)--cycle;  
      \fill[#1] (\pgf@[email protected]) ([xshift=-\pgflinewidth]\pgf@[email protected]) arc
                          (0:180:\insiderad-\pgflinewidth)--cycle;
      \fill[#2] (\pgf@[email protected]) ([xshift=\pgflinewidth]\pgf@[email protected])  arc
                           (180:360:\insiderad-\pgflinewidth)--cycle;            %  \end{scope}   
         }}}}}  
 \makeatother  

\begin{document}

\Huge  

\begin{tikzpicture}
  \node[shape=circle split,
    draw=gray!40,
    line width=1mm,text=white,font=\bfseries,
    circle split part fill={blue!50,red!50}
    ] at (5,5) {text\nodepart{lower}lower};
 \end{tikzpicture} 
 \begin{tikzpicture}
 \node[name=s,
    shape=circle split,
    draw=gray!40,
    line width=10mm, minimum width =5cm,
    circle split part fill={blue!50,red!50}
    ] at (5,5) {text\nodepart{lower}lower};
\end{tikzpicture}
\begin{tikzpicture}
\node[name=s,
    shape=circle split,
    draw=gray!40,line width=2mm,
    circle split part fill={blue!50,red!50}
    ] at (5,5) {Big text\nodepart{lower} very big lower};
\end{tikzpicture} 
\end{document} 

enter image description here

A workaround (the first idea):

\documentclass[11pt]{scrartcl}
\usepackage{tikz}
\usetikzlibrary{shapes,backgrounds,calc}

\begin{document}

\Huge
\begin{tikzpicture}
  \node[name=s,shape=circle split,draw=gray!40,line width=4mm,minimum size=8cm] {text\nodepart{lower}lower};
  \foreach \anchor/\placement in
    {north west/above left, north/above, north east/above right,
     west/left, center/below, east/right,
     mid west/right, mid/above, mid east/left,
     base west/left, base/below, base east/right,
     south west/below left, south/below, south east/below right,
     text/left, lower/left, 130/above}
     \draw[shift=(s.\anchor)] plot[mark=x] coordinates{(0,0)}
       node[\placement] {\scriptsize\texttt{(s.\anchor)}}; 

\begin{scope}[on background layer]
    \fill[blue!50] (s.base) ([xshift=-4mm]s.east) arc (0:180:4cm-2mm)--cycle;
    \fill[red!50] (s.base) ([xshift=4mm]s.west) arc (180:360:4cm-2mm)--cycle;  
\end{scope}
\end{tikzpicture}
\end{document}

enter image description here

It's not easy to make a style from this code. Finally it was possible !

5
  • You are right. I tried it but I got an error perhaps with a problem of syntax. Thanks ! May 13, 2012 at 10:48
  • Wow, this is just awesome. It worked perfectly. Thanks a lot @Altermundus! May 13, 2012 at 14:39
  • 1
    Thanks, but I corrected several bugs and modified the code several times, perhaps small bugs also may still exist. May 13, 2012 at 15:20
  • 1
    @AlainMatthes: this is quite handy, however it does not accept none as a fill, could you point me to a solution for that? ANy chance this makes it into TikZ?
    – ted
    Jun 24, 2013 at 8:40
  • Is there any reason why using \nodepart[fill=black!20]{upper} and \nodepart[fill=red!20]{lower} does not work? (hope I got the syntax correct) ; the pgf manual suggests it should be doable using \nodepart[⟨options⟩]{⟨part name⟩} on page 232.
    – Ted Black
    Jun 12, 2023 at 14:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .