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.

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.

share|improve this question
    
Is cheating allowed with arcs? Because it's really easy that way :) –  percusse Feb 27 '13 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. –  Douglas S. Stones Feb 27 '13 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 Feb 27 '13 at 22:35
    
That sounds suitable for what I want. –  Douglas S. Stones Feb 27 '13 at 22:42
add comment

2 Answers 2

up vote 6 down vote accepted

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

share|improve this answer
    
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 Feb 27 '13 at 22:54
add comment

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

share|improve this answer
add comment

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.