2

I want to create a rectangle Box with three intersected circles:

\documentclass[a4paper,11pt,fleqn]{scrartcl}
\usepackage{pgf,tikz}
\usetikzlibrary{arrows,shadows,decorations.pathreplacing,intersections,positioning,fit,calc,backgrounds}

\def\firstcircle{(0,0) circle (1.5cm)}
\def\secondcircle{(60:2.1cm) circle (1.5cm)}
\def\thirdcircle{(0:2.1cm) circle (1.5cm)}

\begin{document}
\begin{figure}[H]
\centering
\begin{tikzpicture}
\begin{scope}
\clip \firstcircle;
\clip \secondcircle;
\fill[red] \thirdcircle;
\end{scope}
\node (firstcircle)   {};
\node (secondcircle)  {};
\node (thirdcircle)  {};
\draw[name=first] \firstcircle node[below] (A) {$A$};
\draw[name=second] \secondcircle node [above] (B) {$B$};
\draw[name=third] \thirdcircle node [below] (C) {$C$};
\node (box) [fit=(firstcircle)(secondcircle)(thirdcircle), inner sep=1cm,draw,rounded corners] {};
\end{tikzpicture}
\end{figure}
\end{document}

enter image description here

My Problem is: The rectangle should go around all cirles.

  • your question isn't very clear, the code shown produces the error ! LaTeX Error: Unknown float option 'H'. and it isn't clear how you want to change the output, which has intersecting circles already. – David Carlisle Apr 17 '17 at 11:21
  • The code works fine. But the rectangle ist not aound all circles. It is only in the first circle – David Apr 17 '17 at 11:23
  • well if that is the question put that in the question:-) – David Carlisle Apr 17 '17 at 11:24
  • The problem is that your nodes (firstcircle), (secondcircle) etc are just nodes of minimum size at the origin. Add some text to them and you'll see it. You have to make nodes with circle shape to make the fit thing work. – Rmano Apr 17 '17 at 11:48
5

Like this:

enter image description here

I significantly change your code, circle are drawn as nodes:

\documentclass[a4paper,11pt,fleqn]{scrartcl}
\usepackage{pgf,tikz}
\usetikzlibrary{arrows,shadows,decorations.pathreplacing,intersections,positioning,fit,calc,backgrounds}

\def\firstcircle{(0,0) circle (1.5cm)}
\def\secondcircle{(60:2.1cm) circle (1.5cm)}
\def\thirdcircle{(0:2.1cm) circle (1.5cm)}

\begin{document}
\begin{figure}%[H]
\centering
    \begin{tikzpicture}[
    C/.style = {circle, draw, minimum size=30mm},% C as circle, minimum size is circle diameter
    F/.style = {draw, rounded corners, inner sep=1cm}% F as fit node
                        ]
\node (first)   [C] at (0,0)    {$A$};
\node (second)  [C] at (60:2.1) {$B$};
\node (third)   [C] at ( 0:2.1) {$B$};
\node (box) [F, fit=(first)(second)(third)] {};
\begin{scope}
\clip \firstcircle;
\clip \secondcircle;
\fill[red] \thirdcircle;
\end{scope}
\end{tikzpicture}
\end{figure}
\end{document}
  • @David, glad to hear this. Happy TeX-ing. – Zarko Apr 17 '17 at 11:49

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.