# How to make circle with colored halves?

In my math equations, I'd like to use a circle symbol which has the top and bottom half colored at a specific color. Ideally with a separating line at the diameter. The symbol should also work if I use it as a superscript in math mode.

So something like

What would be an approach to achieve that?

A solution with TikZ:

• The size adapts to the current math style. The example uses the size of letter A.

• The line width decreases with smaller line styles.

Full example:

\documentclass{article}
\usepackage{tikz}

\makeatletter
\newcommand*{\twohalfcircle}[2]{%
\ensuremath{%
\mathord{% change accordingly to the symbol type
\mathpalette{\@twohalfcircle{#1}{#2}}{}%
}%
}%
}
\newdimen\@twohalfcircle@dimen
\newdimen\@twohalfcircle@linewidth
\newcommand*{\@twohalfcircle}[4]{%
% #1: bottom color
% #2: top color
% #3: math style
% #4: unused
\sbox0{$#3A$}%
\@twohalfcircle@dimen=\ht0 %
\@twohalfcircle@linewidth=.06\@twohalfcircle@dimen
.5\@twohalfcircle@dimen
- .5\@twohalfcircle@linewidth
}%
\begin{tikzpicture}[
baseline=-.5\@twohalfcircle@dimen,
x=\@twohalfcircle@dimen,
y=\@twohalfcircle@dimen,
line width=\@twohalfcircle@linewidth,
]
\filldraw[fill={#1}] circle[];
\filldraw[fill={#2}]
-- cycle
;
\end{tikzpicture}
}
\makeatother

\begin{document}
$\twohalfcircle{green}{yellow} ^{\twohalfcircle{blue}{red}^{\twohalfcircle{orange}{cyan}}}$
\end{document}


• Nice. It would be nicer if the line width change according to radius. – Sigur Aug 15 '15 at 11:42
• @Sigur, yes, I was already preparing it, see the updated answer. – Heiko Oberdiek Aug 15 '15 at 11:46
• Wow, that's pretty nice. I didn't guess how much little tuning there is. – Gerenuk Aug 15 '15 at 12:19