# Aligning two semicircles

I'm making \item commands with coloured circles. One needs to be two colours, i.e. two semicircles which form a single circle.

I currently have this, which superimposes both circles:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\newcommand*\reditem{\item[{\tikz[baseline=-3]{\node[shape=circle,draw,fill=red,inner sep=4pt] (char) {};}}]}
\newcommand*\redblueitem{\item[{\tikz[baseline=-3]{
\node[shape=semicircle,rotate=90,fill=red,inner sep=3pt](char) {};
\node[shape=semicircle,rotate=270,fill=blue,inner sep=3pt] (char) {};}
}]}

\begin{document}
\begin{frame}
\begin{itemize}
\reditem test red
\redblueitem test redblue
\end{itemize}
\end{frame}
\end{document}


How can I adjust this to form a nice two-colour circle?

-
Try adding line width=0pt,anchor=south to both nodes. I had to guess what packages/tikz-libraries you're using, please consider adding a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. –  Loop Space Jan 8 '13 at 13:51
@AndrewStacey I added dummy test code for a small beamer document. I had no idea there were different tikz libraries. –  rubenvb Jan 8 '13 at 13:55
Does that compile for you? For me, I get a complaint about the semicircle shape which is fixed by loading the shapes.geometric library (as in Jake's answer). –  Loop Space Jan 8 '13 at 13:56
@AndrewStacey sorry about that, fixed and expanded. –  rubenvb Jan 8 '13 at 13:58
No problem. It just makes it easier to diagnose so although it wasn't an stumbling block this time then it's a good habit to get into. –  Loop Space Jan 8 '13 at 14:05

You need to both align them using their south anchors (which are located in the middle of the straight edge), and set the line width=0pt so there's no gap:

\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\begin{document}
\newcommand*\redblueitem{\item[{\tikz[baseline=-3]{
\node[shape=semicircle,rotate=90,fill=red,inner sep=3pt, anchor=south, outer sep=0pt](char) {};
\node[shape=semicircle,rotate=270,fill=blue,inner sep=3pt, anchor=south, outer sep=0pt] (char) {};}
}]}

\begin{itemize}
\redblueitem Test
\end{itemize}
\end{document}


A simpler way to achieve this might be to use \paths instead of nodes. Here's one approach in which I've defined a macro that contains the desired circle radius, so you can easily adjust the size of your circles:

\documentclass{beamer}
\usepackage{tikz}

}}]}

\begin{document}
\begin{frame}
\begin{itemize}
\reditem test red
\redblueitem test redblue
\end{itemize}
\end{frame}
\end{document}

-
Interesting that line width=0pt and outer sep=0pt have the same effect. –  Loop Space Jan 8 '13 at 13:56
@AndrewStacey: Not really, since outer sep is initially defined as .5\pgflinewidth =) –  Jake Jan 8 '13 at 13:59
Great, thanks! This is really helpful. The only problem I have now is that the two semicircles are aligned differently than a single circle. I suppose this is easily fixable by setting the anchor point location 3pt to the right, but I have no idea how to tell tikz that. –  rubenvb Jan 8 '13 at 14:00
Incidentally, after messing around with the parameters to the \nodes then I agree with Jake that paths are easier to ensure that they are the same size. –  Loop Space Jan 8 '13 at 14:13
You sir, are the bomb! Thanks for all your help! –  rubenvb Jan 8 '13 at 14:57

You can use the calc tikzlibrary:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{shapes,calc}

\newcommand*\redblueitem{\item[{\tikz[baseline=-3]{
\node[shape=semicircle,rotate=90,fill=red,inner sep=3pt] (char) {};
\node[shape=semicircle,rotate=270,fill=blue,inner sep=3pt] at ($(char)+(6pt,0)$) {};}
}]}

\begin{document}

\begin{itemize}
\redblueitem something
\end{itemize}

\end{document}


or you can work at the lowest level (PGF):

\documentclass{article}

\usepackage{tikz}

\newcommand*\RBitem{\item[{\tikz[baseline=-3]
\def\r{5pt}
\pgfpathmoveto{\pgfpoint{0pt}{0pt}}
\pgfpathlineto{\pgfpoint{0pt}{\r}}
\pgfpatharc{90}{270}{\r}
\pgfsetfillcolor{red}
\pgfusepath{fill}
\pgfpathmoveto{\pgfpoint{0pt}{0pt}}
\pgfpathlineto{\pgfpoint{0pt}{\r}}
\pgfpatharc{90}{-90}{\r}
\pgfsetfillcolor{blue}
\pgfusepath{fill};}]}

\begin{document}

\begin{itemize}
\RBitem something
\end{itemize}

\end{document}


with the "same" output:

-