LaTeX forum ⇒ Graphics, Figures & TablestikZ | Diagram for Set Relation and Functions Topic is solved

Information and discussion about graphics, figures & tables in LaTeX documents.
sachinrajsharma
Posts: 35
Joined: Sun Apr 08, 2012 5:48 am

tikZ | Diagram for Set Relation and Functions

Postby sachinrajsharma » Thu Nov 22, 2012 8:23 am

Hi,

the introduced source code is not giving output and showing some error.
  1. \documentclass[10pt,a4paper]{article}
  2. \usepackage{tikz}
  3. \usepackage{pgfplots}
  4.  
  5.  
  6. \begin{document}
  7.  
  8. One - One \\
  9. \begin{tikzpicture}
  10.  
  11.  
  12. \pgfpathellipse{\pgfpoint{1cm}{0cm}}
  13. {\pgfpoint{0.2cm}{2cm}}
  14. {\pgfpoint{-0.7cm}{0.7cm}}
  15. \pgfusepath{draw}
  16. \pgfpathellipse{\pgfpoint{5cm}{0cm}}
  17. {\pgfpoint{0.2cm}{2cm}}
  18. {\pgfpoint{-0.7cm}{0.7cm}}
  19. \pgfusepath{draw}
  20. \draw [->](1,1.8)--(5,1.8)
  21.  
  22. \draw (1,1)--(5,1)
  23. (1,1)node[left]{2};
  24. \draw (1,0)--(5,0)
  25. (1,0)node[left]{3};
  26. \draw (1,-1)--(5,-1)
  27. (1,-1)node[left]{4};
  28.  
  29. \end{tikzpicture}
  30.  
  31. \end{document}

Request you to please help.


Regards,
Sachin

Tags:

kaiserkarl13
Posts: 586
Joined: Tue Mar 25, 2008 5:02 pm
Location: Columbia, Missouri, USA

Postby kaiserkarl13 » Thu Nov 22, 2012 8:34 am

I got this to work by commenting out the pgfplots package and adding a semicolon at the end of line 20.

sachinrajsharma
Posts: 35
Joined: Sun Apr 08, 2012 5:48 am

Postby sachinrajsharma » Thu Nov 22, 2012 4:18 pm

thanks a lot ...its working now..thanks again..

Sachin

User avatar
localghost
Site Moderator
Posts: 9206
Joined: Fri Feb 02, 2007 12:06 pm
Location: Braunschweig, Germany

Postby localghost » Thu Nov 22, 2012 6:13 pm

The pgfplots package is not the culprit. kaiserkarl13 already pointed out what to do. But there is a much smarter way to get such set projections by using proper tikZ syntax and respective libraries.
  1. \documentclass[11pt]{article}
  2. \usepackage{tikz}
  3. \usetikzlibrary{fit,shapes}
  4.  
  5. \begin{document}
  6. \begin{tikzpicture}[
  7. >=stealth,
  8. bullet/.style={
  9. fill=black,
  10. circle,
  11. minimum width=1pt,
  12. inner sep=1pt
  13. },
  14. projection/.style={
  15. ->,
  16. thick,
  17. shorten <=2pt,
  18. shorten >=2pt
  19. },
  20. every fit/.style={
  21. ellipse,
  22. draw,
  23. inner sep=0pt
  24. }
  25. ]
  26. \foreach \y/\l in {1/d,2/c/,3/b,4/a}
  27. \node[bullet,label=left:$\l$] (a\y) at (0,\y) {};
  28.  
  29. \foreach \y/\l in {1/4,2/3,3/2,4/1}
  30. \node[bullet,label=right:$\l$] (b\y) at (4,\y) {};
  31.  
  32. \node[draw,fit=(a1) (a2) (a3) (a4),minimum width=2cm] {} ;
  33. \node[draw,fit=(b1) (b2) (b3) (b4),minimum width=2cm] {} ;
  34.  
  35. \draw[projection] (a1) -- (b4);
  36. \draw[projection] (a2) -- (b2);
  37. \draw[projection] (a3) -- (b1);
  38. \draw[projection] (a4) -- (b3);
  39. \end{tikzpicture}
  40. \end{document}

For details please refer to the package manual. The output is attached.


Thorsten
Attachments
utmp.png
utmp.png (6.28 KiB) Viewed 5180 times
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 9 guests