18

I am looking for a way to do something like in the image below

5
  • It would be a reasonably simple diagram in tikz
    – Guido
    Oct 25, 2012 at 3:37
  • 1
    Could you describe in words what you're looking for and what specifically you're having trouble with?
    – doncherry
    Oct 25, 2012 at 3:46
  • 1
    What have you tried so far? It is much appreciated if you show your efforts so far.
    – gerrit
    Oct 25, 2012 at 7:45
  • I am just drawing in Visio and including as a picture, which is a terrible idea.
    – Pablo
    Oct 28, 2012 at 11:37
  • BTW, this image is just a sample I found on the web. Nothing to do with the article I am writing.
    – Pablo
    Oct 28, 2012 at 11:38

4 Answers 4

23

One option using TikZ:

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

\definecolor{myblue}{RGB}{56,94,141}
\begin{document}

\begin{tikzpicture}[line width=1pt,>=latex]
\sffamily
\node (a1) {Anu};
\node[below=of a1] (a2) {Ashu};
\node[below=of a2] (a3) {Jenny};
\node[below=of a3] (a4) {Cathy};

\node[right=4cm of a1] (aux1) {};
\node[below= 0.5cm of aux1] (b1) {Raaz};
\node[below=of b1] (b2) {Jonathan};
\node[below=of b2] (b3) {Fred};
\node[right=4cm of a4] (aux2) {};

\node[shape=ellipse,draw=myblue,minimum size=3cm,fit={(a1) (a4)}] {};
\node[shape=ellipse,draw=myblue,minimum size=3cm,fit={(aux1) (aux2)}] {};

\node[below=1.5cm of a4,font=\color{myblue}\Large\bfseries] {Domain};
\node[below=1.5cm of aux2,font=\color{myblue}\Large\bfseries] {Range};

\draw[->,myblue] (a1) -- (b1.170);
\draw[->,myblue] (a2) -- (b1.190);
\draw[->,myblue] (a3) -- (b2.175);
\draw[->,myblue] (a4.20) -- (b2.190);
\end{tikzpicture}

\end{document}

enter image description here

12

Another solution if you need to adapt the size of the map. if you want to scale the picture it's preferable to avoid fit. It's possible also that you want to draw the same ellipses. In this case you can do that

\documentclass{article}          
\usepackage{tikz}
\usetikzlibrary{arrows}

\definecolor{myblue}{RGB}{56,94,141}
\begin{document}

\begin{tikzpicture}[scale=.75]
\draw[ultra thick,myblue] (0,0) circle [x radius=1.5cm, y radius=5cm]
                    (6,0) circle [x radius=1.5cm, y radius=5cm];

\node[font=\color{myblue}\Large\bfseries] at (0,-6) {Domain};
\node[font=\color{myblue}\Large\bfseries] at (6,-6) {Range};  

\node (a1)  at (0,3)  {Anu};
\node (a2) at (0,1)   {Ashu};
\node (a3) at (0,-1)  {Jenny};
\node (a4) at (0,-3)  {Cathy};

\node[circle] (b1) at (6,2)  {Raaz}; 
 % I used circle to get a fine position of the arrows without a complicated code
\node[circle] (b2) at (6,0)  {Jonathan};
\node[circle] (b3) at (6,-2) {Fred};

\draw[thick,->,myblue] (a1.east) -- (b1);
\draw[thick,->,myblue] (a2.east) -- (b1);
\draw[thick,->,myblue] (a3.east) -- (b2);
\draw[thick,->,myblue] (a4.east) -- (b2);
\end{tikzpicture}    
\end{document} 

It's possible to define some styles to get a better code. It's possible to use some variables to draw automatically some parts of the code.

Update 2

We can add some styles :

\documentclass{article}          
\usepackage{tikz}
\usetikzlibrary{arrows}

\definecolor{myblue}{RGB}{56,94,141}
\newcommand\xsetpos{6}

\begin{document}

\begin{tikzpicture}[scale=.75,
                    arrow/.style={thick,->,myblue},
                    set name/.style={font=\color{myblue}\Large\bfseries\sf},
                    set/.style={ultra thick,myblue},
                    every node/.style={circle},
                    font=\sf
                    ]
\draw[set] (0,0) circle [x radius=1.5cm, y radius=5cm]
           (\xsetpos,0) circle [x radius=1.5cm, y radius=5cm];

\node[set name] at (0,-6) {Domain};
\node[set name] at (\xsetpos,-6) {Range};  

\node (a1) at (0,3)  {Anu};
\node (a2) at (0,1)  {Ashu};
\node (a3) at (0,-1) {Jenny};
\node (a4) at (0,-3) {Cathy};

\node (b1) at (\xsetpos,2)  {Raaz};
\node (b2) at (\xsetpos,0)  {Jonathan};
\node (b3) at (\xsetpos,-2) {Fred}; 

\begin{scope}[arrow]
  \draw (a1.east) -- (b1);
  \draw (a2.east) -- (b1);
  \draw (a3.east) -- (b2);
  \draw (a4.east) -- (b2); 
\end{scope}

\end{tikzpicture}    
\end{document} 

enter image description here

2
  • 1
    Don't forget the sans-serif font in question. :) Oct 25, 2012 at 9:53
  • @ガベージコレクタ The question is about drawing, the font is not a real problem here but I updated my answer. Oct 25, 2012 at 16:53
12

There is no need for using absolute coordinates, which make things only complicated:

\documentclass[dvipsnames]{article}
\usepackage{pst-node}
\begin{document}
\begin{center}
FindFathersMap

\def\arraystretch{2 }
\tabular{c@{\hspace{3cm}}c}
\psovalbox[fillstyle=solid,fillcolor=blue!10]{%
\tabular{c}    % left names
    \rnode[r]{Anu}{Anu}\\
    \rnode[r]{Ashu}{Ashu}\\
    \rnode[r]{Jenny}{Jenny}\\
    \rnode[r]{Cathy}{Cathy}
\endtabular}
&
\psovalbox[fillstyle=solid,fillcolor=blue!10]{%
\tabular{c}    % right names
    \rnode[l]{Raaz}{Raaz}\\
    \rnode[l]{Jonathan}{Jonathan}\\
    \rnode[l]{Fred}{Fred}
\endtabular}
\\
\textcolor{NavyBlue}{\bfseries Domain} & \textcolor{NavyBlue}{\bfseries Range}
\endtabular
 \psset{linecolor=NavyBlue,nodesep=6pt,arrows=->,arrowscale=2}
 \ncline{Anu}{Raaz}    \ncline{Ashu}{Raaz}   \ncline{Jenny}{Jonathan}   \ncline{Cathy}{Jonathan}
\end{center}
\end{document}

enter image description here

0
7

Just for fun with PSTricks.

enter image description here

\documentclass[pstricks,dvipsnames]{standalone}
\usepackage{pst-node}
\renewcommand\familydefault{\sfdefault}
\begin{document}
\begin{pspicture}(-4,-3.5)(4,3.5)
    % title
    \rput[b](0,3){FindFathersMap}
    % left names
    \rput(-2.5,2.25){\rnode[r]{Anu}{Anu}}
    \rput(-2.5,0.75){\rnode[r]{Ashu}{Ashu}}
    \rput(-2.5,-0.75){\rnode[r]{Jenny}{Jenny}}
    \rput(-2.5,-2.25){\rnode[r]{Cathy}{Cathy}}
    % right names
    \rput(2.5,1.5){\rnode[l]{Raaz}{Raaz}}
    \rput(2.5,0){\rnode[l]{Jonathan}{Jonathan}}
    \rput(2.5,-1.5){\rnode[l]{Fred}{Fred}}
    % settings
    \psset{linecolor=NavyBlue,nodesep=6pt,arrows=->,arrowinset=0,arrowscale=0.75}
    % left ellipse
    \psellipse(-2.5,0)(1.5,3)
    % right ellipse
    \psellipse(2.5,0)(1.5,3)
    % arrow connections
    \ncline{Anu}{Raaz}
    \ncline{Ashu}{Raaz}
    \ncline{Jenny}{Jonathan}
    \ncline{Cathy}{Jonathan}
    % left bottom label
    \uput[-90](-2.5,-3){\textcolor{NavyBlue}{\bfseries Domain}}
    % right bottom label
    \uput[-90](2.5,-3){\textcolor{NavyBlue}{\bfseries Range}}
\end{pspicture}
\end{document}

Descriptions:

If you are new to PSTricks, the following descriptions will get you up and running quickly with PSTricks.

  • \rput[b](0,3){FindFathersMap} will put the bottom point of the box enclosing the text to point (0,3). If you don't specify the optional reference [b], then by default the center of the box will be placed at (3,0).
  • \rnode[<ref point>]{<content>}{<nodename>} is used to enclose a non-zero dimensional object with a hypothetical box node named <nodename> where the reference point is determined by [<ref point>]. If you set [r], for example, then the reference point is at the right side of the box node.
  • we use \rput and \rnode together to move a non-zero dimensional object and enclose it with named node.

The remaining descriptions are left for my next edit.

Another method with psmatrix

enter image description here

\documentclass[preview,dvipsnames,border={9mm 0pt 7.4mm 1pt}]{standalone}
\usepackage{pst-node}
\renewcommand\familydefault{\sfdefault}

\begin{document}
\begin{preview}
\psmatrix[colsep=0.5,rowsep=0.5,mnode=r]
    &FindFathersMap\\
    [ref=r]Anu\\
    &&[ref=l]Raaz\\
    Ashu\\
    [name=Left]&& [name=Right] \rnode[l]{Jonathan}{Jonathan}\\
    [ref=r]Jenny\\
    &&[ref=l]Fred\\
    [ref=r]Cathy\\
    \textcolor{NavyBlue}{\bfseries Domain}&&\textcolor{NavyBlue}{\bfseries Range}
\endpsmatrix
\end{preview}
\psset{linecolor=NavyBlue,nodesep=6pt,arrows=->,arrowinset=0,arrowscale=0.75}
\psellipse(Left)(1.5,3.4)
\psellipse(Right)(1.5,3.4)
% arrow connections
\ncline{2,1}{3,3}
\ncline{4,1}{3,3}
\ncline{6,1}{Jonathan}
\ncline{8,1}{Jonathan}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .