3

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 enter image description here

What would be an approach to achieve that?

7

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
\newdimen\@twohalfcircle@radius
\newcommand*{\@twohalfcircle}[4]{%
  % #1: bottom color
  % #2: top color
  % #3: math style
  % #4: unused
  \sbox0{$#3A$}%
  \@twohalfcircle@dimen=\ht0 %
  \@twohalfcircle@linewidth=.06\@twohalfcircle@dimen
  \pgfmathsetlength\@twohalfcircle@radius{%
    .5\@twohalfcircle@dimen
    - .5\@twohalfcircle@linewidth
  }%
  \begin{tikzpicture}[
    baseline=-.5\@twohalfcircle@dimen,
    x=\@twohalfcircle@dimen,
    y=\@twohalfcircle@dimen,
    radius=\@twohalfcircle@radius,
    line width=\@twohalfcircle@linewidth,
  ]
    \filldraw[fill={#1}] circle[];
    \filldraw[fill={#2}]
      (-\@twohalfcircle@radius, 0)
      arc(180:360:\@twohalfcircle@radius)
      -- cycle
    ;
  \end{tikzpicture}
}
\makeatother

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

Result

  • 1
    Nice. It would be nicer if the line width change according to radius. – Sigur Aug 15 '15 at 11:42
  • 1
    @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

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.