Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to add some numbers at 3 places in Venn program. But I don't know how to do that.

\documentclass{letter}
\usepackage[english]{babel}
\usepackage{tikz}
\def\secondcircle{(210:1.75cm) circle (2.5cm)}
\def\thirdcircle{(330:1.75cm) circle (2.5cm)}
\begin{document}
\begin{tikzpicture}
\begin{scope}
\clip \secondcircle;
\fill[cyan] \thirdcircle;
\end{scope}
\draw \secondcircle node [text=black,below left] {$B$};
\draw \thirdcircle node [text=black,below right] {$C$};
\end{tikzpicture}
\end{document}

enter image description here

share|improve this question
1  
\node at (0,0) {zero}; is for the origin (0,0). The other coordinates you can obtains using polar coordinates. For example, the center of the left circle has angle 210 and radius 1.75. If you change the angle you can pass to other points inside the white area. –  Sigur Dec 29 '13 at 14:58
add comment

4 Answers

up vote 7 down vote accepted

Based on your tikz code, this attempt defines two internal name called B and C for the two circles and uses them as reference points where you can use many skills to place your text. For examples, above, below, left, right= xx cm of reference points. above right/left, below right/left= xx cm of reference are also at your disposal. You need \tikzlibrary{positioning}.

enter image description here

Code:

\documentclass{letter}
\usepackage[english]{babel}
\usepackage{tikz}
\usetikzlibrary{positioning}
\def\secondcircle{(210:1.75cm) circle (2.5cm)}
\def\thirdcircle{(330:1.75cm) circle (2.5cm)}
\begin{document}
\begin{tikzpicture}
\begin{scope}
\clip \secondcircle;
\fill[cyan] \thirdcircle;
\end{scope}
\draw \secondcircle node(B) [text=black,below left] {$B$};
\draw \thirdcircle node (C)[text=black,below right] {$C$};
\node[left= 1cm of B]{1};
\node[right= 1cm of C]{4};
\node[right= 1.2 cm of B]{23};
\end{tikzpicture}
\end{document}
share|improve this answer
add comment

Here is a way of doing it using PSTricks:

\documentclass{article}

\usepackage{pstricks}

\newcommand*\circB{\pscircle(2,2){2}}
\newcommand*\circC{\pscircle(4,2){2}}

\begin{document}

\begin{pspicture}(6,4)
\begin{psclip}{\circB}
 \psset{fillstyle = solid, fillcolor = blue!60}
 \circC
\end{psclip}
\circB
\circC
\rput(1.1,2){$B$}
\rput(4.9,2){$C$}
\rput(3,2){$1,2,3,4$}
\end{pspicture}

\bigskip

\begin{pspicture}(6,4)
\begin{psclip}{}
 \psset{fillstyle = solid, fillcolor = blue!60}
 \circB
 \psset{fillcolor = white}
 \circC
\end{psclip}
\circB
\circC
\rput(1.1,2){$B$}
\rput(4.9,2){$C$}
\rput(3,2){$1,2,3,4$}
\end{pspicture}

\end{document}

output2

share|improve this answer
    
Why does the right black border around the blue area have different thickness? –  Sigur Dec 29 '13 at 15:10
    
@Sigur I was do to the clipping. I've change the order of the macros, and the drawing is now as it should be. –  Svend Tveskæg Dec 30 '13 at 5:30
    
Thanks for your reply! One more question. If I just want to fill B-C, how I could I do that? –  Hinn Dec 30 '13 at 15:23
    
@Hinn What is B-C? –  Svend Tveskæg Dec 30 '13 at 15:45
    
@Svend Tveskag B-C means B \cap \complement_C –  Hinn Dec 30 '13 at 16:00
add comment

You can use the calc library to calculate relative node positions, like here:

\documentclass{letter}
\usepackage[english]{babel}
\usepackage{tikz}
\usetikzlibrary{calc}
\def\secondcircle{(210:1.75cm) circle (2.5cm)}
\def\thirdcircle{(330:1.75cm) circle (2.5cm)}
\begin{document}
\begin{tikzpicture}
\begin{scope}
\clip \secondcircle;
\fill[cyan] \thirdcircle;
\end{scope}
\draw \secondcircle node [text=black,below left] (B) {$B$};
\draw \thirdcircle node [text=black,below right] (C) {$C$};
\node at ($(B)!-0.25!(C)$) {1};
\node at ($(B)!0.5!(C)$) {2,3};
\node at ($(B)!1.25!(C)+(0,.5cm)$) {4};
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
Thanks for your reply! One more question. If I just want to fill B-C, how I could I do that? –  Hinn Dec 30 '13 at 15:35
1  
I will change the order or the comands: first I will fill the B circle with the desired color (\draw[fill=yellow] ...) and then I will execute the scope environment (the \clip will overwrite the B \cap C). If you desire only B-C, then use fill[white] inside the scope. –  Diego Dec 30 '13 at 20:57
add comment

The stackinset macro allows text (or graphics) to be overlaid an existing image. The insets can be nested. Location of the inset is specified in figure dimensions, relative to the left/center/right and top/center/bottom of the underlying image. In this case, I specified offsets relative the center-center of the image.

In this case, the insets are text mode, but they can be set in math mode, \parboxes, or anything, really.

\documentclass{letter}
\usepackage[english]{babel}
\usepackage{stackengine}
\usepackage{tikz}
\def\secondcircle{(210:1.75cm) circle (2.5cm)}
\def\thirdcircle{(330:1.75cm) circle (2.5cm)}
\begin{document}
\stackinset{c}{-2.2cm}{c}{-.25cm}{1}{%
\stackinset{c}{}{c}{}{234}{%
\stackinset{c}{2cm}{c}{0.5cm}{5}{%
\begin{tikzpicture}
\begin{scope}
\clip \secondcircle;
\fill[cyan] \thirdcircle;
\end{scope}
\draw \secondcircle node [text=black,below left] {$B$};
\draw \thirdcircle node [text=black,below right] {$C$};
\end{tikzpicture}%
}}}
\end{document}

enter image description here

share|improve this answer
    
Thanks for your reply! One more question. If I just want to fill (B-C), how I could I do that? –  Hinn Dec 30 '13 at 15:35
    
What do you mean "fill"? My answer allows text to be positioned and overlaid upon an existing image. If the question concerns the use of tikz to color fill portions of the drawing, that would require someone else's expertise to answer. –  Steven B. Segletes Dec 30 '13 at 15:41
    
Sorry for my expression. I mean that I only want to color part B(except B \cap C). –  Hinn Dec 30 '13 at 16:04
1  
@Hinn If I understand your question, you would like to inset text in one, not three locations. In that case, you can delete the two unwanted \stackinset lines, and two of the three closing right braces (after \end{tikzpicture}) –  Steven B. Segletes Dec 30 '13 at 16:18
    
It seems like the first comment is a standard one. I'm not even sure the OP has looked at the code before posting the follow-up question. :( –  Svend Tveskæg Dec 30 '13 at 20:47
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.