TikZ에서 이 원을 색칠하는 방법은 무엇입니까?

TikZ에서 이 원을 색칠하는 방법은 무엇입니까?

스크린샷처럼 이 MWE의 출력에 색상을 지정하려면 어떻게 해야 합니까?

\documentclass{book}
\usepackage{tikz} 
\begin{document}
\begin{center}
\begin{tikzpicture}
\draw [thick] (3.25,-2) circle (1.5cm)      node[right=.7cm, above=.4cm] {$A$};
\draw [thick] (2.5,-3.5) circle (1.5cm)     node[left=.7cm,] {$B$};
\draw [thick] (4,-3.5) circle (1.5cm)       node[right=.7cm] {$C$};
\draw [thick](0,0) rectangle (6.5,-5.5)     node[left=6cm, above=.3cm] {$M$};
\end{tikzpicture}
\end{center}
\end{document}

여기에 이미지 설명을 입력하세요

답변1

가장 쉬운 방법은 원을 먼저 채운 다음 그리는 것입니다.

\documentclass{book}
\usepackage{tikz}
\begin{document}
\begin{center}
\begin{tikzpicture}
\fill[gray!50] (3.25,-2) circle (1.5cm);
\fill[gray!50] (2.5,-3.5) circle (1.5cm);
\fill[white] (4,-3.5) circle (1.5cm);
\draw [thick] (3.25,-2) circle (1.5cm)      node[right=.7cm, above=.4cm] {$A$};
\draw [thick] (2.5,-3.5) circle (1.5cm)     node[left=.7cm,] {$B$};
\draw [thick] (4,-3.5) circle (1.5cm)       node[right=.7cm] {$C$};
\draw [thick](0,0) rectangle (6.5,-5.5)     node[left=6cm, above=.3cm] {$M$};
\end{tikzpicture}
\end{center}
\end{document}

여기에 이미지 설명을 입력하세요

적절하게 클리핑하여 각 영역에 색상을 지정할 수 있습니다.

\documentclass{book}
\usepackage{tikz}
\begin{document}
\begin{center}
\begin{tikzpicture}
\fill[gray!50] (3.25,-2) circle (1.5cm);
\fill[gray!50] (2.5,-3.5) circle (1.5cm);
\fill[yellow] (4,-3.5) circle (1.5cm);
\begin{scope}
  \clip (2.5,-3.5) circle (1.5cm);
  \fill[blue!50] (3.25,-2) circle (1.5cm);
\end{scope}
\begin{scope}
  \clip (3.25,-2) circle (1.5cm);
  \fill[red!50] (4,-3.5) circle (1.5cm);
\end{scope}
\begin{scope}
  \clip (2.5,-3.5) circle (1.5cm);
  \fill[olive!50] (4,-3.5) circle (1.5cm);
\end{scope}
\begin{scope}
  \clip (2.5,-3.5) circle (1.5cm);
  \clip (3.25,-2) circle (1.5cm);
  \fill[green!50] (4,-3.5) circle (1.5cm);
\end{scope}
\draw [thick] (3.25,-2) circle (1.5cm)      node[right=.7cm, above=.4cm] {$A$};
\draw [thick] (2.5,-3.5) circle (1.5cm)     node[left=.7cm,] {$B$};
\draw [thick] (4,-3.5) circle (1.5cm)       node[right=.7cm] {$C$};
\draw [thick](0,0) rectangle (6.5,-5.5)     node[left=6cm, above=.3cm] {$M$};
\end{tikzpicture}
\end{center}
\end{document}

여기에 이미지 설명을 입력하세요

관련 정보