Graphics, Figures & TablestikZ | Diagram for Set Relation and Functions

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

tikZ | Diagram for Set Relation and Functions

Post by sachinrajsharma »

Hi,

the introduced source code is not giving output and showing some error.

Code: Select all

\documentclass[10pt,a4paper]{article}
\usepackage{tikz}
\usepackage{pgfplots}


\begin{document}

One - One \\
\begin{tikzpicture}


\pgfpathellipse{\pgfpoint{1cm}{0cm}}
{\pgfpoint{0.2cm}{2cm}} 
{\pgfpoint{-0.7cm}{0.7cm}}
\pgfusepath{draw}
\pgfpathellipse{\pgfpoint{5cm}{0cm}}
{\pgfpoint{0.2cm}{2cm}}
{\pgfpoint{-0.7cm}{0.7cm}}
\pgfusepath{draw}
\draw [->](1,1.8)--(5,1.8)

\draw (1,1)--(5,1)
(1,1)node[left]{2};
\draw (1,0)--(5,0)
(1,0)node[left]{3};
\draw (1,-1)--(5,-1)
(1,-1)node[left]{4};

\end{tikzpicture}

\end{document}
Request you to please help.


Regards,
Sachin

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

kaiserkarl13
Posts: 707
Joined: Tue Mar 25, 2008 5:02 pm

tikZ | Diagram for Set Relation and Functions

Post by kaiserkarl13 »

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

Re: tikZ | Diagram for Set Relation and Functions

Post by sachinrajsharma »

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

Sachin
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

tikZ | Diagram for Set Relation and Functions

Post by localghost »

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.

Code: Select all

\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{fit,shapes}
 
\begin{document}
  \begin{tikzpicture}[
    >=stealth,
    bullet/.style={
      fill=black,
      circle,
      minimum width=1pt,
      inner sep=1pt
    },
    projection/.style={
      ->,
      thick,
      shorten <=2pt,
      shorten >=2pt
    },
    every fit/.style={
      ellipse,
      draw,
      inner sep=0pt
    }
  ]
    \foreach \y/\l in {1/d,2/c/,3/b,4/a}
      \node[bullet,label=left:$\l$] (a\y) at (0,\y) {};

    \foreach \y/\l in {1/4,2/3,3/2,4/1}
      \node[bullet,label=right:$\l$] (b\y) at (4,\y) {};

    \node[draw,fit=(a1) (a2) (a3) (a4),minimum width=2cm] {} ;
    \node[draw,fit=(b1) (b2) (b3) (b4),minimum width=2cm] {} ;

    \draw[projection] (a1) -- (b4);
    \draw[projection] (a2) -- (b2);
    \draw[projection] (a3) -- (b1);
    \draw[projection] (a4) -- (b3);
  \end{tikzpicture}
\end{document}
For details please refer to the package manual. The output is attached.


Thorsten
Attachments
utmp.png
utmp.png (6.28 KiB) Viewed 12988 times
Post Reply