Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
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

2 Answers 2

up vote 11 down vote accepted

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}

\def\rubensradius{4pt}

\newcommand*\reditem{\item[{\tikz [baseline=-0.8*\rubensradius]{\path [fill=red, draw=blue] (0,0) circle [radius=\rubensradius-0.5\pgflinewidth];}}]}
\newcommand*\redblueitem{\item[{\tikz [baseline=-0.8*\rubensradius]{
    \path [fill=red] (0,\rubensradius) arc [start angle=90, delta angle=180, radius=\rubensradius];
    \path [fill=blue] (0,-\rubensradius) arc [start angle=270, delta angle=180, radius=\rubensradius];
}}]}

\begin{document}
\begin{frame}
\begin{itemize}
  \reditem test red
  \redblueitem test redblue
\end{itemize}
\end{frame}
\end{document}
share|improve this answer
    
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
1  
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
1  
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:

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.