5

Question: In the following figure, how can I shade the region marked "here"?

How can I shade "here"?

I'm guessing there is an elegant solution via the intersections library, but I'm not sufficiently familiar with it.

Here's a minimal working example of my LaTeX code:

\documentclass[crop]{standalone}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
  \draw[thin,dashed,<->] (0.5,0) to (7.5,0);

  \coordinate (a) at (1,0);
  \coordinate (b) at (3,0);
  \coordinate (c) at (5,0);
  \coordinate (d) at (7,0);

  \draw (a) to[bend left=80] (c);
  \draw (b) to[bend left=80] (d);

  \node (x) at (4,0.3) {\small here};
\end{tikzpicture}

\end{document}

I don't need the word "here", it's just there to point to the region I want shaded.

4
  • Is cheating allowed with arcs? Because it's really easy that way :)
    – percusse
    Commented Feb 27, 2013 at 22:12
  • Hmm... it is somewhat "cheating". It depends on whether there's a decent method without arcs. To use arcs, I'd need to adjust several such figures for consistency, which wouldn't be the end of the world, but I'd avoid if there's an alternative. Commented Feb 27, 2013 at 22:20
  • Would it be okay if you had to repeat the paths once each? in that, case, you could use a clip.
    – Jake
    Commented Feb 27, 2013 at 22:35
  • That sounds suitable for what I want. Commented Feb 27, 2013 at 22:42

2 Answers 2

6

Solution

\begin{tikzpicture}
  \draw[thin,dashed,<->] (0.5,0) to (7.5,0);

  \coordinate (a) at (1,0);
  \coordinate (b) at (3,0);
  \coordinate (c) at (5,0);
  \coordinate (d) at (7,0);

  \draw (a) to[bend left=80] (c);
  \draw (b) to[bend left=80] (d);

  \clip (a) to [bend left=80] (c) -- cycle;
  \fill[yellow]  (b) to[bend left=80] (d) -- cycle;

  \node (x) at (4,0.3) {\small here};
\end{tikzpicture}

Update

In the above solution the right edge of the yellow region is thinner, due to the clipping. It can be solved if the arcs are drawn after the yellow fill. It is neccesary to use a scope to "undo" the clipping when drawing the arcs:

Better

\begin{tikzpicture}
  \draw[thin,dashed,<->] (0.5,0) to (7.5,0);

  \coordinate (a) at (1,0);
  \coordinate (b) at (3,0);
  \coordinate (c) at (5,0);
  \coordinate (d) at (7,0);
  \begin{scope}
    \clip (a) to [bend left=80] (c) -- cycle;
    \fill[yellow]  (b) to[bend left=80] (d) -- cycle;
  \end{scope}
  \draw (a) to[bend left=80] (c);
  \draw (b) to[bend left=80] (d);
  \node (x) at (4,0.3) {\small here};
\end{tikzpicture}

Update 2: Look ma, no clipping!

And of course this is big cheating. Just for fun.

\begin{tikzpicture}
  \draw[thin,dashed,<->] (0.5,0) to (7.5,0);

  \coordinate (a) at (1,0);
  \coordinate (b) at (3,0);
  \coordinate (c) at (5,0);
  \coordinate (d) at (7,0);

  \fill[yellow] 
        (a) to[bend left=80]  (c);
  \fill[white, even odd rule] 
        (a) to[bend left=80] (c) -- (b) to[bend left=80]  (d);
  \draw (a) to[bend left=80] (c);
  \draw (b) to[bend left=80] (d);

  \node (x) at (4,0.3) {\small here};
\end{tikzpicture}

Cheating

1
  • I was also playing with the idea of using the even odd rule and trying to fill a path which makes loops around the to-be-filled region, but I was unable to think of a path which makes an odd number of "turns" around the center region and an even number of turns around the other two. Probably is not possible, but I didn't find the proof either.
    – JLDiaz
    Commented Feb 27, 2013 at 22:54
7

Well it's still cheating but I guess not that bad. You can scope the drawing to keep the clipping local.

\documentclass[crop,tikz]{standalone}
\begin{document}
\begin{tikzpicture}
  \draw[thin,dashed,<->] (0.5,0) to (7.5,0);

  \coordinate (a) at (1,0);
  \coordinate (b) at (3,0);
  \coordinate (c) at (5,0);
  \coordinate (d) at (7,0);

  \draw (a) to[bend left=80] (c);
  \clip[preaction={draw}] (b) to[bend left=80] (d);

  \node (x) at (4,0.3) {};
  \shade (a) to[bend left=80] (c);

\end{tikzpicture}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .