6

I am trying to fill a path consisting of two semicircles, and I only want the area between them to be filled. The following code doesn't work correctly.

\documentclass{article}
\usepackage{tikz}
\usepackage[active,pdftex,tightpage]{preview}
\PreviewEnvironment[]{tikzpicture}
\begin{document}
 \begin{tikzpicture}
 \filldraw[yellow,draw=black] (0em,0em) arc[radius=1em, start angle=180, end angle=0]
   (2em,0em) --  (2em,-1em) arc[radius=1em, start angle=0, end angle=180]
   (0em,-1em) -- (0em,0em);
 \end{tikzpicture}
\end{document}

What I get is this:

Incorrect filling

Also, if I use the path for clipping, the same incorrect filled area is used. Can someone figure out how to fill the area inside the drawn semicircles (non-convex area) only?

  • (+1) for completing your code even though you already had answers. That makes your question more useful to future readers. – cfr Jan 30 '15 at 23:19
11

You need to specify a continuous path for the fill for this to work neatly. So don't specify coordinates which you've already drawn to as that introduces a discontinuity:

\documentclass[tikz,border=5pt]{standalone}
\begin{document}
\begin{tikzpicture}
\filldraw[yellow,draw=black]
  (0em,0em)
    arc[radius=1em, start angle=180, end angle=0]
    --  (2em,-1em)
    arc[radius=1em, start angle=0, end angle=180]
    -- (0em,0em);
\end{tikzpicture}
\end{document}

yellow

4
\documentclass[tikz,border=4]{standalone}
\begin{document}
  \begin{tikzpicture}
  \filldraw[yellow,draw=black] (0,0) arc[radius=1em, start angle=0, end angle=180]
  --  ++(0em,-1em) arc[radius=1em, start angle=180, end angle=0]
  -- ++(0em,1em) -- cycle;
\end{tikzpicture}
\end{document}

enter image description here

  • 1
    Thanks for the correct answer, but I selected cfr's solution since it came with an explanation. – Sameer Jan 30 '15 at 22:25

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.