4

I am novice when it comes to Tikz. I have three Venn Diagrams. Fore some reason the text inside the Venn diagrams start at the lower half of the node. Is there a way to automatically align/fit it to the size of the shape?

\def\firstcircle{(0,0) circle (2.1cm)}
\def\secondcircle{(55:3.5cm) circle (2.1cm)}
\def\thirdcircle{(0:3.5cm) circle (2.1cm)}
\centering
\begin{tikzpicture}[>=stealth,on grid,auto] 
\begin{scope}[shift={(4cm,-15cm)}, fill opacity=0.5]
        \fill[gray!30!white] \firstcircle;
        \fill[blue!30!white] \secondcircle;
        \fill[cyan!60!white] \thirdcircle;
        \draw \firstcircle node[below] {
        \begin{tabular}{c}
        \textbf{Economic Layer}: \\
        A\\
        B\\
        C\\
        D
        \end{tabular}
        };
        \draw \secondcircle node [above,text width=2cm,align=center] {
         \begin{tabular}{c}
         \textbf{Technology Layer}\\
         A \& B\\
         C \& D
         \end{tabular}
         };
        \draw \thirdcircle node [below,text width=2cm,align=center] {
        \begin{tabular}{c}
        \textbf{Social  Layer}\\
        A\\
        B\\
        C
        \end{tabular}
        };
    \end{scope}
\end{tikzpicture}   
  • Sorry if you find this discouraging, but I can't remember ever learning anything of any value from a Venn diagram. I suspect they are never really helpful. I think the reason is that in practice it is clear whether various sets of objects have a common overlap. I would like to see a useful example of a Venn diagram, exposing some counterintuitive structure in some intuitively well understood sets. – Benjamin McKay Mar 26 '15 at 21:08
4

If you want the text in the centre then you can add the text centered option to the tikz picture.

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

\begin{document}
\def\firstcircle{(0,0) circle (2.1cm)}
\def\secondcircle{(55:3.5cm) circle (2.1cm)}
\def\thirdcircle{(0:3.5cm) circle (2.1cm)}

\centering
\begin{tikzpicture}[>=stealth,on grid,auto, text centered] 
\begin{scope}[shift={(4cm,-15cm)}, fill opacity=0.5]
        \fill[gray!30!white] \firstcircle;
        \fill[blue!30!white] \secondcircle;
        \fill[cyan!60!white] \thirdcircle;
        \draw \firstcircle node[] {
        \begin{tabular}{c}
        \textbf{Economic Layer}: \\
        A\\
        B\\
        C\\
        D
        \end{tabular}
        };
        \draw \secondcircle node [] {
         \begin{tabular}{c}
         \textbf{Technology Layer}\\
         A \& B\\
         C \& D
         \end{tabular}
         };
        \draw \thirdcircle node [] {
        \begin{tabular}{c}
        \textbf{Social  Layer}\\
        A\\
        B\\
        C
        \end{tabular}
        };
    \end{scope}
\end{tikzpicture}   

\end{document}

enter image description here

By my eye there is still a problem with this though as the bottom left circle labeled "economic layer" overlaps slightly. To fix this manually you could use the xshift and yshiftoptions for each node to fine tune the positioning.

  • magic touch, works fine! – sosruko Mar 26 '15 at 11:03
3

Probably you still don't know, but nodes can have different shapes. The basic ones are rectangular and circular but you can find come more in shapes tikzlibrary.

In your code, circles and text are different entities and you have to adjust them. Another solution could be to use circular nodes:

\node[draw, circle, minimum size=4.2cm, fill=gray!30, align=center, opacity=0.5, text opacity=1] 
    {\\
    \textbf{Economic Layer}: \\
    A\\
    B\\
    C\\
    D
    };

This command draws a circle with minimum radius=2.1cm (if inner text needs more space, the node will grow) and text aligned to center. By declaring align option, there's no need to include tabulars inside the node but \\ is still valid as newline command.

Instead of repeating all these options in every node, you can declare a .style:

mycircle/.style={draw, circle, minimum size=4.2cm, align=center, 
                  fill=#1, opacity=0.5, text opacity=1}

This style has one parameter (#1) which corresponds to filling color.

Your code could be written like:

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[mycircle/.style={draw, circle, minimum size=4.2cm, align=center, 
                    fill=#1, opacity=0.5, text opacity=1}] 
        \node[mycircle=gray!30] {\\
        \textbf{Economic Layer}: \\
        A\\
        B\\
        C\\
        D
        };
        \node[mycircle=blue!30] at (60:3.5cm) {
         \textbf{Technology Layer}\\
         A \& B\\
         C \& D
         };
        \node[mycircle=cyan!60] at (0:3.5cm) {
        \textbf{Social  Layer}\\
        A\\
        B\\
        C
        };
\end{tikzpicture}   
\end{document}

enter image description here

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.