How to create a graph of our own in LaTeX

Hi, I want to create the following picture in LaTeX. How can I do this?

-
Welcome to TeX.SX. In its current form, your question might not receive many answers. Please take a look at the How to Ask-page and try to improve your question according to the guidance found there. This may require you to show some effort on your part in terms of attempting a solution. – lockstep Apr 23 '14 at 10:21

This is an attmpt: use of tikz where an ellipse style is defined. Once this is done, it can be used in a node definition as such.

\node[ell] at (x,y) (internal label) {label};


Then use draw to connect this two nodes. Here to[options] can have many selections. Some are shown here.

Options: none -- for a line.

bent (left,right) = angle -- for curve.

in=angle1, out=angle2 -- for curve with different in/out angles.

\draw[->] (A) to[options] (B)


Code

\documentclass[12pt]{article}
\usepackage[paper size={10cm,10cm}]{geometry}
\usepackage{tikz}
\usetikzlibrary{shapes}

\begin{document}

\tikzset{
ell/.style={draw,ellipse,minimum height=3em,minimum width=5em},
}

\begin{tikzpicture}
\node[ell] at (0,0) (A) {A};
\node[ell] at (5,0) (B) {B};
\draw[->,>=stealth] (A) to[bend left=30] (B);
\draw[->,>=stealth] (B) to[bend left=30] (A);
\end{tikzpicture}
\end{document}

-
thanks, How can i add a text above the arrows? – user3482383 Apr 27 '14 at 6:51
Take this for example \draw[->,>=stealth] (A) to[bend left=30] node[above,pos=0.99] {A} (B); or pos=0.9 etc. You need to add usetikzlibrary{positioning} for use of pos=xx. – Jesse Apr 27 '14 at 7:04

You can create a picture inside of LaTeX itself, with the picture environment. You can also use a package that works inside of LaTeX, such as PSTricks or TikZ. Or, you can draw your stuff in a stand-alone program that knows about LaTeX, such as MetaPost or Asymptote. Personally, I like the latter.

Here is a try at your diagram in Asymptote. (It uses the node.asy module, and on my Ubuntu machine I used ASYMPTOTE_DIR="node-4.0/modules" asy -fpdf test to invoke Asymptote.)

import node;
size(1inch,0);
// define edge style
defaultdrawstyle=drawstyle(p=fontsize(8pt)+fontcommand("\ttfamily"),

node a=scircle("\small $A$");
node b=scircle("\small $B$");

// calculate nodes position
real u=1cm;
a << eright(1.6u) << b;

draw(a,b);

draw(a..bend..b,
b..bend..a);


It produces this picture.

-
Can i use these lines (copy and paste them) in Latex? or i need any special package? I am new with Latex – user3482383 Apr 23 '14 at 11:15
There are lots of options; I can tell you what I do. Make a subdirectory of your .tex's directory called asy. Put this file in it. Fetch the node-4.0.zip and unzip it in that directory. Invoke Asymptote as I described above. Then in your LaTeX file use \includegraphics{asy/twonodes.pdf} to bring in the graphic (I use pdflatex so the .pdf is OK), after putting \usepackage{graphicx} in the preamble. – Jim Hefferon Apr 23 '14 at 12:06

I recommend you PSTRICKS and PST-NODE packages

You can see PST-NODE PDF

------------ Example Mini, with only nodes and lines --------------

\documentclass[pstricks,border=12pt]{standalone}
%
\usepackage[utf8]{inputenc}
\usepackage{eurosym}
\usepackage{pst-node}

\begin{document}

\begin{pspicture}(-2,-2)(12,6) %\malla

\rput(4.5,3){\circlenode{IL}{\textcolor{red}{I like}}}
\rput(8.5,3.5){\circlenode{L}{\textcolor{blue}{\LaTeX}}}
\rput(6.5,-0.5){\circlenode{G}{\textcolor{blue}{\footnotesize{Galicia(Spain)}}}}

\ncarc[arcangle=44]{->}{IL}{L}

\ncarc[arcangle=22]{->}{IL}{L}
\nbput*{\small Yes}   % This line show error on compiling.

\ncarc[arcangle=22]{->}{L}{IL}
\ncput*{\small No}   % This l

\ncarc[arcangle=8]{->}{L}{G}
\ncarc[arcangle=-22,linewidth=0.05,linecolor=red]{->}{G}{L}

\ncarc[arcangle=-22,linewidth=0.05,linecolor=red,linestyle=dashed]{->}{IL}{G}

\rput(1,2){\circlenode{V}{\textcolor{blue}{Vigo}}}
\rput(1,5){\circlenode{C}{\textcolor{magenta}{Coru\~na}}}

\rput(3,2){\circlenode{S}{\textcolor{red}{Scq}}}
\rput(3,5){\circlenode{P}{\textcolor{green}{Po}}}

\ncarc[arcangle=33]{->}{V}{C}
\nbput*{\small 45 \euro}   % This line show error on compiling.

\ncarc[arcangle=11]{->}{S}{P}
\ncput*{\small 25 \euro }

\ncarc[arcangle=75]{->}{S}{P}
\ncput*{\small{\blue 15 \euro} }

\rput(2,0){This is a test.}
\rput(8,-2){Esto é unha proba.}

\end{pspicture}
\end{document}


Other example with any other things:

\documentclass[pstricks,border=12pt]{standalone}
%
\usepackage[utf8]{inputenc}
\usepackage{eurosym}
\usepackage{pst-node}

\begin{document}

\begin{pspicture}(-2,-2)(12,6) %\malla
% \psaxes{<->}(3,3)

\rput(4.5,5){\circlenode{IL}{\textcolor{red}{I like}}}
\rput(4.5,1.5){\circlenode{L}{\textcolor{blue}{\LaTeX}}}
\ncarc[arcangle=33]{->}{IL}{L}
\nbput*{\small Yes}   % This line show error on compiling.
\ncarc[arcangle=33]{->}{L}{IL}
\ncput*{\small No}   % This l

\psaxes[linewidth=1.2pt,labels=none,ticks=none]{<->}(0,0)(-1,-1)(10,6)
\psgrid[linecolor=lightgray,gridwidth=0.0075](0,0)(6,3)
%subgriddots=5

\rput(1,2){\circlenode{V}{\textcolor{blue}{Vigo}}}
\rput(1,5){\circlenode{C}{\textcolor{magenta}{Coru\~na}}}
\rput(3,2){\circlenode{S}{\textcolor{red}{Scq}}}
\rput(3,5){\circlenode{P}{\textcolor{green}{Po}}}

\ncarc[arcangle=33]{->}{V}{C}
\nbput*{\small 45 \euro}   % This line show error on compiling.

\ncarc[arcangle=11]{->}{S}{P}
\ncput*{\small 25 \euro }

\ncarc[arcangle=75]{->}{S}{P}
\ncput*{\small{\blue 15 \euro} }

\psbezier[linecolor=blue, linewidth=0.04,linestyle=dashed]{*-*}(4,-0.5)(6,6)(8,-2)(10,2)

\rput(8,3){Esto é unha proba.}

\pscurve[linecolor=blue, linewidth=0.065]{o-o}(6,5)(7,4)(8,5.8)(9,5.8)(10,4)(11,6)

\psdots[dotsize=0.4](10,2)

\pscustom{
\pscurve(8,-2)(10,2)(11.5,0)
%\psline(11.5,1)(11.5,-1)
\fill[fillstyle=solid,fillcolor=lightgray,opacity=0.74]}

\pscircle[linecolor=red,fillcolor=blue,fillstyle=solid,linewidth=0.05,linestyle=dashed,opacity=0.56](10,3){1.5}
\pscircle[linecolor=green,fillcolor=red,fillstyle=solid,linewidth=0.05,linestyle=dashed,opacity=0.56](8,3){1.5}

\rput(8,2){Esto é unha proba.}

\end{pspicture}
\end{document}

-

You should considere using Tikz/pgf.

A good introduction can be found on the main documentation : http://linorg.usp.br/CTAN/graphics/pgf/base/doc/pgfmanual.pdf

What you need is avalable on page 47.

-