# How to constrain text using multiple shapes in TikZ?

I'm trying to reproduce this graph, using TikZ:

So far, what I got is this:

It's not bad, I don't mind the circles instead of having elipses (not the point of my question anyway)... The problem is: how do I post text inside the three spaces so that LaTeX automatically forces the text inside of those spaces so that if the text is a lot, it might even fit the same shapes? As you can see the preview text, which is lol, goes to the center of the circles which inevitably means being on the circle lines. (You can use any text for the answer, like lipsum, and so on.) My current Tex code is:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[russian]{babel}
\usepackage[landscape]{geometry}
\usepackage{tikz}
\usepackage{subfig}

\begin{document}
% Definition of circles
\def\firstcircle{(0,0) circle (5cm)}
\def\secondcircle{(0:5cm) circle (5cm)}

\colorlet{circle edge}{black}
\colorlet{circle area}{white}

\tikzset{filled/.style={fill=circle area, draw=circle edge, thick},
outline/.style={draw=circle edge, thick}}

\begin{figure}
\begin{tikzpicture}

\draw
\firstcircle node(1) {$lol$}
\secondcircle node(2) {$lol$};

\node[anchor=east] at (current bounding box.west) {\huge{A}};
\node[anchor=west] at (current bounding box.east) {\huge{B}};
\node[anchor=north] at (current bounding box.south) {\huge{C}};

\end{tikzpicture}
\end{figure}

\end{document}

-

I would suggest placing the text using \nodes and then to use the fit library to draw the ellipses around the appropriate nodes; something along these lines:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,positioning,fit}

\begin{document}

\begin{tikzpicture}[node distance=2cm,
every fit/.style={ellipse,ultra thick,draw,inner sep=0pt},
mytext/.style={inner sep=6pt}]

\node[mytext,align=right,rectangle] (a) {some text \\ goes here \\ and spans \\ several\\ lines};
\node[mytext,align=center,rectangle,left=of a] (b) {some text \\ goes here \\ and spans \\ several\\ lines};
\node[mytext,align=left,rectangle,left=of b] (c) {some text \\ goes here \\ and spans \\ several\\ lines};

\node[draw,fit=(a) (b)] {};
\node[draw,fit=(c) (b)] {};
\end{tikzpicture}

\end{document}


Using text width=<length> for the text nodes, the text will wrap automatically.

-
Is there a way to make the text centered? – ozsu Jul 9 '12 at 18:35
@gonzalo-medina If you try to color the ellipse by using fill=, the color is applied over the text. Is there a way to ensure the text is in front? – Trevor Alexander Jan 15 '14 at 2:55

Something like Gonzalo's method but here I fix the shapes. I gave some dimensions to the rectangles and then I placed nodes for texts inside the rectangles. The little advantage is to fix the height of the rectangle. If you don't do that and If a text is higher than another, then the ellipses are asymmetrical.

\documentclass[11pt]{scrartcl}
\usepackage{tikz}
\usetikzlibrary{fit,shapes}

\begin{document}
\def\textfortest { Little text for testing}
\begin{tikzpicture}[txtstyle/.style={minimum width=3cm,minimum height=4cm,draw,inner sep=0pt}]
\node [txtstyle] (n1) {};
\node [txtstyle,xshift=-5cm] (n2) {};
\node [txtstyle,xshift= 5cm] (n3) {};
\node [ellipse,fit=(n1)(n2),draw] {};
\node [ellipse,fit=(n1)(n3),draw] {};

\begin{scope}[every node/.style={text width=3cm,anchor=north west}]
\node  at (n2.north west){\textfortest. \textfortest};
\node  at (n1.north west){\textfortest. \textfortest};
\node  at (n3.north west){\textfortest. \textfortest};
\end{scope}

\end{tikzpicture}
\end{document}


-