4

I have this code:

\begin{tikzpicture}
    \draw (0,0) arc (180:0:1cm);
    \draw (0,0) -- (2cm,0) -- (1cm,1cm)-- (0,0);
\end{tikzpicture}

How can I fill this area?:

Area

Thanks!

8

I think the simplest way is this:

\documentclass[10pt, border=.3cm]{standalone}
\usepackage{tikz}
\begin{document}
    \begin{tikzpicture}
    \draw[fill=gray] (0,0) arc (180:0:1cm);
    \draw[fill=white] (0,0) -- (2cm,0) -- (1cm,1cm)-- (0,0);
\end{tikzpicture}
\end{document}

enter image description here

And if you like the borders gray instead of black:

\documentclass[10pt, border=.3cm]{standalone}
\usepackage{tikz}
\begin{document}
    \begin{tikzpicture}
    \filldraw[gray] (0,0) arc (180:0:1cm);
    \draw[gray, fill=white] (0,0) -- (2cm,0) -- (1cm,1cm)-- (0,0);
\end{tikzpicture}
\end{document}

enter image description here

  • I like the first one. First time I see filldraw command. Thanducks! – manooooh Feb 14 '18 at 9:05
  • 1
    @manooooh ducks are welcome! \filldraw[a-color] is a shortcut for \draw[a-color, fill=a-color], quack! – CarLaTeX Feb 14 '18 at 10:10
8

A straight-forward way would be just to connect your two paths and make it a fill (in case you really want to fill only the two segments):

\documentclass[tikz]{standalone}

\begin{document}

\begin{tikzpicture}
    \fill[gray] (0,0) arc (180:0:1cm) --
                (0,0) -- (2cm,0) -- (1cm,1cm) -- cycle;
\end{tikzpicture}

\end{document}

enter image description here

  • 3
    shorter: ` \fill[gray] (0,0) -- (1,1) -- (2,0) arc (0:180:1);` +1) – Zarko Feb 14 '18 at 9:02
  • 1
    @Zarko do you like code golfing : \fill[gray](,)--(2,0)arc(0:180:1);, shorter ? – Kpym Feb 16 '18 at 22:32
  • @Kpym, very interesting :-). i see this first time. where is documented? – Zarko Feb 16 '18 at 22:37
  • @Zarko that you can delete (0,0) it is obvious because fill do not need a closed curve. That (,) is giving (1,1) is probably a side effect. – Kpym Feb 16 '18 at 22:44

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.