5

I would like to draw the graph displayed in the following picture with TikZ and also do some modifications:

enter image description here

Firstly I want to carry the labels of the nodes to the inside as a second line. For instance inside node a it will display a, and then below (0.5 70/70) (preferably with a smaller font than a).

Moreover I would like to change the sizes of the nodes wrt. the the numeric value displayed in the label. So as an example the node e will be approximately twice as big as node a.

1
  • 2
    Welcome to TeX.sx! Please add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. Commented Apr 19, 2013 at 0:28

2 Answers 2

4

Here's one possibility:

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

\definecolor{myyellow}{RGB}{255,255,150}

\newcommand\mytext[3][\scriptsize]{#2\\#1 #3}
\newcommand\mynode[4][]{%
  \node[mynode,#1,text width=\the\dimexpr#2cm*3] (#3) {\mytext{#3}{#2 #4}}; 
}

\begin{document}

\begin{tikzpicture}[
node distance=2cm,
mynode/.style={
  circle,
  draw,
  fill=myyellow,
  align=center}
]
\mynode{0.67}{d}{(130/61)}
\mynode[below=of d]{0.45}{c}{(130/61)}
\mynode[below=of c]{0.50}{a}{(130/61)} 
\mynode[left=of a]{0.67}{b}{(130/61)} 
\mynode[right=of c]{0.95}{e}{(130/61)}
\draw[->] 
  (d) -- node[rotate=90,below] {\mytext[\normalsize]{0.9}{(72/8)}} (c); 
\draw[->] 
  (c) -- node[rotate=90,below] {\mytext[\normalsize]{0.9}{(72/8)}} (a);
\draw[->] 
  (d) -- node[sloped,below] {\mytext[\normalsize]{0.9}{(72/8)}} (b); 
\draw[->] 
  (e) -- node[sloped,below] {\mytext[\normalsize]{0.9}{(72/8)}} (a); 
\draw[->] 
  (b) to[bend left] node[above] {\mytext[\normalsize]{0.9}{(72/8)}} (a); 
\draw[->] 
  (a) to[bend left] node[below] {\mytext[\normalsize]{0.9}{(72/8)}} (b); 
\end{tikzpicture}

\end{document}

enter image description here

The syntax for the \mynode command is

\mynode[<options>]{<value>}{<name>}{<additional text>}

The optional argument passes <options> to a \node; <value> will be used to internally calculate the node size, and also in the label; <name> will be used for the label and to name the node, <additional text> is the text that will accompany <value> in the label.

3

Here is one way you can have text in the nodes and also have the node scaled to the weight:

enter image description here

Notes:

  • You need to carefully select the value of the \DefaultSize based on the range of your data.
  • As per Qrrbrbirlbel's suggestion I have scaled based on the sqrt of the size parameter so as to keep the area proportional to the weight.

Code:

\documentclass{article}
\usepackage{tikz}

\newcommand*{\DefaultRadius}{1.2cm}%

\tikzset{My Style/.style={circle,draw=black, ultra thick, fill=yellow!40,align=center}}

\newlength{\NodeSize}
\newcommand{\MyNode}[4][]{%
    % #1 = optional node paramaters
    % #2 = label
    % #3 = scale
    % #4 = additional text
    \pgfmathsetlength{\NodeSize}{2*\DefaultRadius*sqrt(#3)}%
    \node [My Style, minimum size=\NodeSize,#1] (#2) {#2 \\ {\tiny #3 #4}}
}%
\begin{document}
\begin{tikzpicture}
\MyNode{d}{1.0}{70/70};
\MyNode[xshift=4.0cm,fill=cyan!25,draw=red]{c}{1.5}{70/70};
\MyNode[xshift=8.0cm,fill=green!20]{c}{0.5}{70/70};
\end{tikzpicture}
\end{document}

You must log in to answer this question.

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