5

How can I fit the text squarely inside the circles without it overlapping like this? enter image description here

\documentclass[tikz,border=12pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
   %\usepgfplotslibrary{external}
%\tikzexternalize
\begin{document}
\def\firstcircle{(90:1cm) circle (2.5cm)}
  \def\secondcircle{(210:2.5cm) circle (2.5cm)}
  \def\thirdcircle{(330:2.5cm) circle (2.5cm)}
  \def\fourthcircle{(90:-3.5cm) circle (2.5cm)}
%\tikzsetnextfilename{4way_venn}
    \begin{tikzpicture}
\begin{scope}[ fill opacity=0.5]
        \fill[red] \firstcircle;
        \fill[green] \secondcircle;
        \fill[blue] \thirdcircle;
    \fill[cyan] \fourthcircle;\end{scope}
%    \begin{scope}
%      \clip \firstcircle;
%      \clip \secondcircle;
%      \clip \thirdcircle;
%\fill[cyan]\fourthcircle;
%    \end{scope}
      \draw \firstcircle node[text=black,above] {CO$_2$ reduction};
      \draw \secondcircle node [text=black, left=1cm] {Cost-effectiveness};
      \draw \thirdcircle node [text=black,right=-0.4cm] {Infection control};
\draw \fourthcircle node [text=black,below=1cm]{Customer satisfaction};

    \end{tikzpicture}
\end{document}
4
  • Is it allowed to overlap with the inner circles?
    – T. Verron
    Jun 6, 2013 at 8:49
  • Preferably it should only cover its own circle.
    – HCAI
    Jun 6, 2013 at 8:52
  • 1
    Ok, then I won't submit it as an answer. A quick workaround to get rid of the overlapping in your case is to tweak the left=1cm option, reducing it a little. That's what is pushing the text so far left. But I understand that you would prefer an automagical solution. :)
    – T. Verron
    Jun 6, 2013 at 8:57
  • @T.Verron ah yes the joy and simplicity of automagic! I see what you are referring to though. In fact I had to place those circles in a rather ad-hoc trial and error way. I would have liked to just position, say the top one, and have the rest fall into place...
    – HCAI
    Jun 6, 2013 at 9:03

1 Answer 1

6

If you fix a certain width to your text, then an align option breaks long lines according the width. A possible manual solution for your example would be:

\documentclass[tikz,border=12pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
   %\usepgfplotslibrary{external}
%\tikzexternalize
\begin{document}
\def\firstcircle{(90:1cm) circle (2.5cm)}
  \def\secondcircle{(210:2.5cm) circle (2.5cm)}
  \def\thirdcircle{(330:2.5cm) circle (2.5cm)}
  \def\fourthcircle{(90:-3.5cm) circle (2.5cm)}
%\tikzsetnextfilename{4way_venn}
    \begin{tikzpicture}
\begin{scope}[ fill opacity=0.5]
        \fill[red] \firstcircle;
        \fill[green] \secondcircle;
        \fill[blue] \thirdcircle;
    \fill[cyan] \fourthcircle;\end{scope}
%    \begin{scope}
%      \clip \firstcircle;
%      \clip \secondcircle;
%      \clip \thirdcircle;
%\fill[cyan]\fourthcircle;
%    \end{scope}
      \draw \firstcircle node[text=black,above, text width=2cm, align=center] {CO$_2$ reduction};
      \draw \secondcircle node [text=black, left, text width=2cm, align=center] {Cost-effectiveness};
      \draw \thirdcircle node [text=black,right, text width=2cm, align=center] {Infection control};
\draw \fourthcircle node [text=black,below, text width=2cm, align=center]{Customer satisfaction};

    \end{tikzpicture}
\end{document}

enter image description here

0

You must log in to answer this question.

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